EE4 compatibility updates:

  • Publisher is EE4 and EE5 compatible, but it does not currently support the Fluid field.
  • Reel is EE4 and EE5 compatible, but it does not currently support the Fluid field.

Ticket: Nested Bloqs variables not parsed in closing tag after first bloq.

Status Resolved
Add-on / Version Bloqs 4.0.9
Severity
EE Version 4.3.6

Jarod Clark

Nov 07, 2018

Description: I have a setup where I’m using nested Bloqs. I’m trying to do a conditional in the close section for a bloq and the variable is only parsed for the first instance of that bloq type.

Here’s an example of my code:

{sections}

    {
!-- ROOTSECTION --}
    {section}
        
<div class="{if theme == 'light'}bg-gradient-light{/if} px-xs relative clearfix" data-block-name="section">
            
{if container == 1}<div class="container mx-auto">{/if}

        {close
:section}
            {container}
            {if container 
== 1}</div>{/if}
        
</div>
        
{/close:section}
    {
/section}
    {
!-- END ROOTSECTION --}

{
/sections} 

As you can see, I have a {container} variable that I’m trying to run a conditional on in the closing tag. The first time this bloq is displayed, everything works fine (and it outputs 1 in this case). The second time I have a bloq of that same type on the page, it’s not parsed and just outputs {container}.

The variable and conditional are properly parsed in the main part of the tag, it’s just whatever is in the {close:section} part that isn’t parsed.

#1

BoldMinded (Brian)

Nov 08, 2018

What is “container”? Is it a block variable or something else? Another custom field?

#2

BoldMinded (Brian)

Nov 08, 2018

Is container an atom?

#3

Jarod Clark

Nov 10, 2018

Sorry for the delay.

“container” is an atom (a field defined in the bloq type). In this case, it’s a toggle field.

#4

BoldMinded (Brian)

Nov 10, 2018

Thanks, I’ll try to replicate it soon and see what the issue is.

#5

BoldMinded (Brian)

Nov 10, 2018

I was not able to replicate this. Here is my section code, which I added a Toggle field too, then added a section > row, section > row to the Bloqs field.

Have you tried a similar conditional with another atom type? E.g. checking if a field value == some text instead of using a Toggle field? What other ways have you tried to debug this?

{section}
            
<div class="container" data-id="{blocks:id}" data-type="section">
            <
h1>{heading}</h1>
            <
p>container{container}</p>
            
{close:section}
             
<div class="closing">{if container}Yep{/if}</div>
            </
div>
            
{/close:section}
        {
/section} 

#6

BoldMinded (Brian)

Nov 10, 2018

#7

Jarod Clark

Nov 11, 2018

I just set up another test page with only 3 top level bloqs, no nesting. It seems it’s the last bloq that isn’t being parsed.

http://www.unleadedsoftware.com/tmp/bloqs-entry.png
http://www.unleadedsoftware.com/tmp/bloqs-frontend.png

#8

Jarod Clark

Nov 11, 2018

And actually, in looking at this a bit closer, in my debug code where I’m outputting the bloqs variables in the close tag, it’s actually outputting the variables from the NEXT bloq, not the current one.

So if you look at that bloqs-frontend image I linked in the previous comment, it should be outputting 1 - white, then 0 - light, then 1 - dark based on the values I have in the bloqs. However, it’s only outputting from the 2nd and 3rd bloqs, and then outputting no parsed values for the last iteration.

Hopefully that helps with tracking this down.

#9

Jarod Clark

Nov 11, 2018

Comment has been marked private.

#10

BoldMinded (Brian)

Nov 11, 2018

Ok, I can see conditionals not parsing correctly, but it appears to only be the Toggle fields, as in its not correctly evaluating “0” as false and “1” as true. The field values are strings, not integers.

Given the following code where container is a Toggle and theme is a dropdown, the theme field conditional appears to be working, just not the Toggle field.

{section}
            
<div class="container" data-id="{blocks:id}" data-type="section">
            <
h1>{heading}</h1>
            <
p>theme{theme} {if theme == "light"}bright{/if}{if theme == "medium"}dull{/if}{if theme == "dark"}boring{/if}</p>
            <
p>container{container} {if container}Yep{/if}</p>
            
{close:section}
             close container
{container}
             
<div class="closing">{if container}Yep{/if}</div>
            </
div>
            
{/close:section}
        {
/section} 

#11

BoldMinded (Brian)

Nov 11, 2018

#12

BoldMinded (Brian)

Nov 11, 2018

Comment has been marked private.

#13

BoldMinded (Brian)

Nov 12, 2018

I think this has something to do with the internal parser. If I explicitly set the toggle field value to false if it has the string value of “0” then the template renders correctly.

Try making this code change:

protected function _parseConditionals($tagdataTagOutputBlockContext $context)
    
{
        
// Compile conditional vars
        
$cond [];
        
$cond array_merge($cond$this->getContextVariables($context));
        
$block $context->getCurrentBlock();

        
// Map column names to their values in the DB
        
foreach ($block->atoms as $atom{
            
// Add this conditional...
            
if ($atom->value === '0'{
                $atom
->value false;
            
}
            $cond[$atom
->definition->shortname] $atom->value;
        
}

        $tagdata 
$this->EE->functions->prep_conditionals($tagdata$cond);

        return 
$tagdata;
    

My latest template code with results:

{section}
            
<div class="container" data-id="{blocks:id}" data-type="section">
            <
h1>{heading}</h1>
            <
p>theme{theme} {if theme == "light"}bright{/if}{if theme == "medium"}dull{/if}{if theme == "dark"}boring{/if}</p>
            <
p>container{container} {if container}Yep{if:else}Nope{/if}</p>
            
{close:section}
             close container
{container}
             
<div class="closing">{if container}Yep{if:else}Nope{/if}</div>
            </
div>
            
{/close:section}
        {
/section} 

#14

BoldMinded (Brian)

Nov 12, 2018

Note, this is when the field is not set to nestable. When I make it nestable I do see the issue of the conditional inside the close tag showing the incorrect value.

#15

BoldMinded (Brian)

Nov 12, 2018

Comment has been marked private.

#16

Jarod Clark

Nov 12, 2018

I installed that build you provided and this does appear to be working properly now.

Here’s output from a test template I set up this morning which was showing incorrect info before I updated:

Start Section
 Container
1
 Theme
white
    

    Start Close Section
     Container
1
     Theme
white
    End Close Section
End Section
    
Start Section
 Container
0
 Theme
light
    

    Start Close Section
     Container
0
     Theme
light
    End Close Section
End Section
    
Start Section
 Container
1
 Theme
dark
    

    Start Close Section
     Container
1
     Theme
dark
    End Close Section
End Section 
#17

BoldMinded (Brian)

Nov 12, 2018

Comment has been marked private.

#18

Jarod Clark

Nov 12, 2018

Just uploaded that latest build, and it all looks to be working fine still.

#19

BoldMinded (Brian)

Nov 12, 2018

Sweeeet. Thanks for checking. I’ll go ahead and close this ticket.

Thanks for pointing out this bug btw, seems its been like this for months and no one has caught it :(

#20

BoldMinded (Brian)

Nov 13, 2018

Jarod, I took another look at the conditional parsing, specifically the {if container} conditional, and found that it was working as intended. You’ll need to change them to {if container == ‘0’} or {if container == ‘1’} in order for it to work. I found this in EE’s core, which I should follow, otherwise some other field that actually contains the value “0” that is not a boolean will not evaluate correctly in the conditional.

/**
  * Cast to EE boolean
  */
 
private function bool($value)
 
{
  
// We do *not* follow the string 0 php casting rule.
  // {if field} should be true if the user entered
  // something. Doesn't matter what it is.
  
if ($value === '0')
  
{
   
return TRUE;
  
}

  
return (bool) $value;
 

Login to reply

Contact

For add-on support, please use the Support section. General inquries and pre-sale questions can be sent to support@boldminded.com.