phalcon volt bitwise operatios?

I need to run the following logic in the volt templates however it seems to be it doesnt support it. ANy ideas on workarounds ?

{% for index, pkey in partnervar %} <input id="{{ key }}[]" name="{{ key }}[]" value="{{ pkey.id }}" type="checkbox"
{% if user.p
body & (1 << (pkey.id - 1)) %} checked {% endif %}> {{ pkey.title }}

fails with the Error Scanning error before ' (1 << (p_key.id.

Hey, i could not find anything about bitwise ops in docs as well :(

However you are free to use php in volt as well. Its not a clean solution, but... :

<?php .... ?>

Another option woud be to extend volt with a function https://docs.phalconphp.com/en/latest/reference/volt.html#extending-volt

Extend volt with function which will calculate your bitwise operation nad return what you want

I think it could also be argued that if you're doing bitwise operations in your view, you shouldn't be doing bitwise operations in your view. Do that in the controller.



4.9k

i dont agree, all this doesnt is mark the checkboxes as selected based on the user selected values, i dont think you should add this presentation logic to controllers, it should be handled by the view itself.

i like the solution of adding the function to the volt compiler...

I think it could also be argued that if you're doing bitwise operations in your view, you shouldn't be doing bitwise operations in your view. Do that in the controller.