htmltwigpimcoretwig-extension

Get current brick ID in twig template?


Currently I am creating custom bricks - sample:

{% set store = [] %}    
{% for i in 1..20 %}
   {% set store = store|merge([(i*8) ~ "px"]) %}
{% endfor %}

{% set heightSel = pimcore_select('heightSel', {
    store: store,
    reload: true,
    width: 100
}) %}

{% if editmode %}
    <div class="container editprop-container no-material">
        <div class="ed-col ed-col-100">
            <label>{{ "Height"|trans }}</label><br/>
            {{ heightSel|raw }}
        </div>
    </div>
{% endif %}

<div class="spacer spacer-{{ heightSel.getData()|default("0px") }}"></div>

Because I want to put the editing options (.editprop-container) into a custom modal I need some unique ID for this brick (such that it does not conflict with other bricks). Is there some possiblity to the the brick ID?

Note: A twig extension would be valid solution, but this does not help me because I do not know how to retrieve some custom ID of an editable anyway.


Solution

  • After experimenting for some time I have solved it by adding randomly generated secondary IDs to the bricks:

     {% set modalTempId = getRandomAlnumString(20) %}
     <span class="edit-modal-opener" data-toggle="modal" data-target="#emo_{{ modalTempId }}"><i class="fal fa-cogs"></i></span>
    
     <!-- Modal -->
     <div class="modal fade" id="emo_{{ modalTempId }}" tabindex="-1" role="dialog" aria-hidden="true">
      ...
     </div>
    

    Still a better answer would be how to get the brick ID, this is a workaround which fulfills the purpose though.