We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53530
    • 3 Posts
    

Hey guys,
    1st time poster here, and i need help! Gonna try and explain it as best as i can.

    Im currently trying to get a value from a template variable, pass that value into my snippet, and have the snippet
    output on the resource. I have tried so many things and cant figure it out.

    <?php
    $output ='';
     
    $content = $modx->resource->getTVValue('content');
    $contentTwo = $modx->resource->getTVValue('2ndcontent');
    $contentThree = $modx->resource->getTVValue('3rdcontent');
     
    if (empty($contentTwo)){
         
        $output ='<div class="col-md-12">'.$content. '</div>';
    return $output;
    }elseif (!isset($contentTwo) && (!empty($contentThree)))  {
      
       $output ='<div class="col-md-6">'.$content.'</div>
                 <div class="col-md-6">'.$contentTwo.'</div>';
     
    return $output;
    }elseif (isset($contentTwo) && (isset($contentThree)) ){
                
        $output = '<div class="col-md-4">'.$content.'</div>
              <div class="col-md-4">'.$contentTwo.'</div>
             <div class="col-md-4">'.$contentThree.'</div>'; 
    }
    return $output;
     
    ?>



    in the chunk i have the call
    [[!menu_call]]


    so basically with the above, im trying to output 3 different layouts depending on if there is anything inside the template variables.
    There has to be a way to get a 3 'if' statement to work please help!!

    I have tried just using template variable input output filters, but can only get "if this" do this else "do this" working. Cant seem to find a way to add a third one in there.
    [[+tv.2ndcontent:isnot=``:then=`
    <div class="col-md-6">[[+content]]</div><div class="col-md-6">[[+tv.2ndcontent]]</div> `]]   
                
    [[+tv.3rdcontent]]`:isnot=``:then=`
           <div class="col-md-4">[[+content]]</div><div class="col-md-4">[[+tv.2ndcontent]]</div><div class="col-md-4">[[+tv.3rdcontent]]</div>
     
    [[+tv.2ndcontent]]`:is=``:then=`
    <div class="col-md-12">[[+content]]</div>
    `:else=``]]


    I dont care which way it can be done, just wish any way would work! haha

    Thanks in advance,






    SOLVED///////////////////

    SO finally worked it out, for anyone else interested here is the code, thanks to Mark Hamstra, for putting me on the right track.

    This is for anyone who wants to output template variables of child resources from a snippet using a getResources Call.

    getResources Call Chunk:

    <div>
      [[!getResources? &parents=`[[*id]]`  &tpl=`TheSnippetTpl` &includeTVs=`1` &includeContent=`1` &sortby=`menuindex` &sortdir=`ASC` &limit=`10`]]
    </div>


    theSnippetTpl Chunk: (calling the values of the template variables within each child resource)

    <div>
    [[!snippet_call? &contentvar=`[[+content]]` &contentTwo=`[[+tv.2ndcontent]]` ]]   
    </div>



    the snippet: if $contentTwo [[+tv.2ndcontent]] variable is empty do this

         <?php
    if (empty($contentTwo)) { 
        return '<div class="row">' . $contentvar . '</div>';    /* output contents of $contentvar - [[+content]] */
    } else {
    
    return ' <div class="row">' . $contentTwo . '</div>' ;   /*else output contents of $contentTwo - [[+tv.2ndcontent]] */ 
    }
    
    



    chunk call within the Parent Resource. this will then output the variables in the child resources
    [[$yourchunk]]


    hope it helps anyone else!