doushan6161 2014-10-27 20:50
浏览 27

高级自定义字段,设置html5画布文本

If anyone would have any references or links to point me in the direction I'd greatly appreciate it. I know I can set canvas text with "context.fillText ("Hello World");" when just doing straight forward canvas.

My question is how would I go about using Advanced Custom Fields (acf) field to as my text variable so the client can set/change the text on their own.

So if I had:

<?php the_field('canvas_text'); ?>

How would I go about setting this as the 'fillText'?

Could I use somehow use the ACF field as a variable that I then use in the canvas js?

  • 写回答

1条回答 默认 最新

  • douyimin1083 2014-11-07 11:11
    关注

    Use wp_localize_script to pass a variable from php to javascript in WordPress, like this:

    wp_localize_script( 'canvas_js', 'canvas_js_localization', array(
        'canvas_text' => get_field( 'canvas_text' )
    ) );
    

    and then use it in your js like this:

    context.fillText (canvas_js_localization.canvas_text)
    

    Of course you have to edit the handle and name to fit your scenario.

    评论

报告相同问题?

悬赏问题

  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'