You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Fuel CMS区块中访问传递的变量?技术咨询

Fixing Variable Access in Fuel CMS Blocks

Hey there, let's get your Fuel CMS block variables working. I see you're trying to pass custom variables to a block but can't access them—here are the most likely fixes:

1. Access Passed Variables Directly (No fuel_var() Needed)

When you pass variables via the vars array in {fuel_block()}, those are available as local Smarty variables in your block template. You don't need to use fuel_var() here—that function is for global, page-level, or config variables, not the ones you explicitly pass to the block.

For example, in your nt_project_card template, replace references like {fuel_var('img')} with {$img} (if you add 'img' => 'path/to/image.jpg' to your vars array), and use your passed variables like this:

<img class="card-img-top" src="{$img}" alt="Project Image">
<div class="card-body">
  <h5 class="card-title">{$project_title}</h5>
  <p class="card-text">{$project_desc}</p>
  <a href="{$project_link}" class="btn btn-primary">View Project</a>
</div>

2. Fix Syntax in Your fuel_block Call

Looking at your code snippet, you're using =&gt; which is HTML-encoded. In your actual template, you need to use the plain Smarty arrow =>—otherwise, Smarty won't parse the array correctly and your variables won't be passed:

{fuel_block(array( 
  'view' => 'nt_project_card', 
  'vars' => array( 
    'project_title' => 'Test Project', 
    'project_desc' => 'Some details about project', 
    'project_link' => 'projects/project1' 
  )
))}

3. Confirm Your Block View is in the Right Place

Make sure nt_project_card.tpl (or .php if using PHP views) lives in the correct directory. Fuel looks for block views in:

  • fuel/app/views/blocks/ (for custom blocks you create)
  • fuel/modules/fuel/views/blocks/ (for core Fuel blocks)

If your block is in a subfolder, adjust the view path accordingly, e.g., 'view' => 'blocks/cards/nt_project_card'.

4. Debug by Printing All Variables

If you're still stuck, add this line to your block template to see every variable available in its scope. This will tell you if your variables are even being passed:

<pre>{$|@print_r}</pre>

If you don't see project_title, project_desc, etc., in the output, go back and double-check the fuel_block syntax and view path—those are the most common culprits here.


内容的提问来源于stack exchange,提问作者ateebahmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:07:53