modx-pro / pdoTools

Library for creating fast snippets for MODX Revolution.
95 stars 87 forks source link

How to run pThumb snippet #141

Closed adamwintle closed 9 years ago

adamwintle commented 9 years ago

I am trying to make a full Fenom chunk for pdoResources output, this is my pdoResources call:

[[pdoResources?
    &parents=`0`
    &limit=`1`

    &includeTVs=`first-image,portals`
    &tvPrefix=``
    &tpl=`article.panel.fenom`  
]]

and my &tpl chunk is

<div class="panel panel-default grow equal-heights">
    <div class="panel-header">
        <div class="image-wrapper">
            <a href="{$uri}"> 
                <img src="[[pthumb? &input=`[[+first-image]]` &options=`w=256&h=290&zc=T`]]" width="265" height="290" class="img-responsive" alt="{$pagetitle}">
            </a>
        </div>
    </div>
    <div class="panel-body">
        <a href="{$uri}">
            <h4><span class="{$link_attributes}"></span> {$pagetitle}</h4>
            <p>{$introtext}</p>
        </a>
    </div>
</div>

Everything is working here except the pThumb snippet, I have tried this:

{$modx->runSnippet("pthumb", [ 
    'input' => $modx->getObject('modResource', $id)->getTVValue('first-image'), 
    'options' => '&w=256&h=290&zc=T' 
])}" 

But this code does not work - how can the Fenom template call another snippet plus is parameters?

bezumkin commented 9 years ago

{$modx} is disabled by default due to security reasons. Better to use {$_modx}

{if $_pls['first-image'] != ''}
    {$_modx->runSnippet("pthumb", [ 
        'input' => $_pls['first-image'], 
        'options' => '&w=256&h=290&zc=T' 
    ])}
{/if}

Access to variable {$_pls} in this case need only because $first-image would not work.

Try to read russian docs about pdoParser.

bezumkin commented 9 years ago

Can I close this?

adamwintle commented 9 years ago

Yes this is working now.