Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hi, is there a way for custom fields to be accessible in a PHP block?

I have a field 'parameter_input_value' in a repeatable, and I'd like to be able to access it's value in order to do some processing on display.
Hi,
is there a way for custom fields to be accessible in a PHP block?

If we use cms:php tag to execute PHP, all the editable regions and variables remain available the normal way. For example, suppose we have a custom field named 'my_region', it's value can be made available to PHP as follows -
Code: Select all
<cms:php>echo("<cms:show my_region />");</cms:php>

or
Code: Select all
<cms:php>
    $my_var = "<cms:show my_region />";
    echo '<h1>' . $my_var . '</h1>';
</cms:php>

Just a small caveat - in the examples above, if the value of 'my_region' happens to contain an unescaped double-quote, PHP will throw a syntax error. For example, suppose if the value of 'my_region' is hello "world",
the $my_var = "<cms:show my_region />"; statement will then evaluate to
$my_var = "hello "world"";
Clearly that is a syntax error for PHP.

To prevent this from happening, we can use the cms:addslashes tag -
Code: Select all
<cms:php>
    $my_var = "<cms:addslashes><cms:show my_region /></cms:addslashes>";
    echo '<h1>' . my_var . '</h1>';
</cms:php>

Hope this helps.
Thank you very much!
3 posts Page 1 of 1
cron