We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Volt macros default values

Hi. I want to write macros for my notifications settings list. I build easy macros:

{%- macro row(span_text, site_value, email_value, disable_site=false) %}
    <tr class="options-row">
        <td><span class="infoHS">{{ span_text }}</span></td>
        <td><input type="checkbox" {% if site_value %}checked="checked"{% endif %} {% if disable_site %}disabled="disabled"{% endif %} /></td>
        <td><input type="checkbox" {% if email_value %}checked="checked"{% endif %} /></td>
    </tr>
{%- endmacro %}

And then i call this:

{{ row("Some rus string", 0, 1) }}
{{ row("Some rus string", 1, 1) }}
{{ row("Some rus string", 1, 1, true) }}

disable_site mean, that the site value cannot be overrided by user, for example friends invitation notification.

But when i run this, i give this:

Macro row was called without parameter: disable_site
// Some stacktrase....

Volt generate this template:

<?php function vmacro_row($__p) { if (isset($__p[0])) { $span_text = $__p[0]; } else { if (isset($__p['span_text'])) { $span_text = $__p['span_text']; } else {  throw new \Phalcon\Mvc\View\Exception("Macro row was called without parameter: span_text");  } } if (isset($__p[1])) { $site_value = $__p[1]; } else { if (isset($__p['site_value'])) { $site_value = $__p['site_value']; } else {  throw new \Phalcon\Mvc\View\Exception("Macro row was called without parameter: site_value");  } } if (isset($__p[2])) { $email_value = $__p[2]; } else { if (isset($__p['email_value'])) { $email_value = $__p['email_value']; } else {  throw new \Phalcon\Mvc\View\Exception("Macro row was called without parameter: email_value");  } } if (isset($__p[3])) { $disable_site = $__p[3]; } else { if (isset($__p['disable_site'])) { $disable_site = $__p['disable_site']; } else {  throw new \Phalcon\Mvc\View\Exception("Macro row was called without parameter: disable_site");  } }  ?>
    <tr class="options-row">
        <td><span class="infoHS"><?php echo $span_text; ?></span></td>
        <td><input type="checkbox" <?php if ($site_value) { ?>checked="checked"<?php } ?> <?php if ($disable_site) { ?>disabled="disabled"<?php } ?> /></td>
        <td><input type="checkbox" <?php if ($email_value) { ?>checked="checked"<?php } ?> /></td>
    </tr><?php } ?>

And as you can see, disable_site is required! I'm trying with changing value to "false", 0, 12341234, etc, but it don't help me.

Phalcon 1.3.2, Windows

@phalcon, maybe you can help me?



43.9k

Hi,

try with

disable_site:false

Nope ((

Syntax error, unexpected token COLON


43.9k

Bad. And what about to pass parameters as an array:


{%- macro row(options) %}
    <tr class="options-row">
        <td><span class="infoHS">{{ options.span_text }}</span></td>
        ....

// and
{{ row(["Some rus string", 0, 1]) }}
edited Dec '14

Yes, i can use array, but https://docs.phalcon.io/en/latest/reference/volt.html#macros there i see my solution and it's doen't work. Bug?



43.9k

You're right

edited Dec '14

I create issue for this, but it's lead me to another trouble: https://github.com/phalcon/cphalcon/issues/3179. Maybe you have "bad solution" which will help me get around this problem?

Happy New Year!