3

a lot of people are comparing stash with nsm_transplant, so I was wondering if the same thing could be achieved with stash:

{exp:nsm_transplant:body}
 {cf_textarea}
 {cf_images_matrix}
     {exp:nsm_transplant:content id="image_{row_count}"}
      {exp:ce_img:pair src="{image_url:url}" width="200"}<img src="{made}" width="{width}" height="{height}" alt="{gv_alt}" />{/exp:ce_img:pair}
     {/exp:nsm_transplant:content}
 {/cf_images_matrix}
{/exp:nsm_transplant:body} 

that way all the {image_x} needles within the {cf_textarea} get replaced with the corresponding tag.

would be nice if stash could do that!

EDIT: Follow up for more complex example

Now, while your example (see next answer) works like a charm, I've tested a few more cases:

Complex example in standalone mode:

{preload_replace:pre_prefix="static"}
{exp:channel:entries channel="ch_static" entry_id="1130" limit="1" disable="categories|member_data|pagination"}
    {exp:stash:parse process="end"}
        {cf_{pre_prefix}_block_matrix}
            <article class="content_block">
                {if title}<h1>{title}</h1>{/if}
                {if media AND text}
                    <div class="image">
                        {media}
                    </div>
                    <div class="text">
                        {text}
                    </div>
                {if:else}
                    {text}{media}
                {/if}
            </article><!-- end content_block -->
        {/cf_{pre_prefix}_block_matrix}
    {/exp:stash:parse}          

    {cf_{pre_prefix}_images_matrix}
        {exp:stash:set name="bild_{row_count}" type="snippet"}
            {if image_zoom == "y"}
                <a class="modalbox_zoom img_link" title="{image_url:title}" href="{exp:ce_img:pair src='{image_url:url:max_size}' width='1200' height='800'}{made}{/exp:ce_img:pair}">
            {/if}
            {exp:switchee variable="{image_size}" parse="inward"}
                {case value="left"}
                    {exp:ce_img:pair src="{image_url:url:max_size}" width="255" allow_scale_larger="yes"}<img src="{made}" class="{image_alignement}" width="{width}" height="{height}" alt="{title} {image_url:title} {image_url:desc} {gv_alt}" />{/exp:ce_img:pair}
                {/case}
                {case value="right"}
                    {exp:ce_img:pair src="{image_url:url:max_size}" width="311" allow_scale_larger="yes"}<img src="{made}" class="{image_alignement}" width="{width}" height="{height}" alt="{title} {image_url:title} {image_url:desc} {gv_alt}" />{/exp:ce_img:pair}
                {/case}
                {case value="full"}
                    {exp:ce_img:pair src="{image_url:url:max_size}" width="600" allow_scale_larger="yes"}<img src="{made}" class="{image_alignement}" width="{width}" height="{height}" alt="{title} {image_url:title} {image_url:desc} {gv_alt}" />{/exp:ce_img:pair}
                {/case}
                {case value="untouched"}
                    <img src="{image_url:url}" width="{image_url:width}" height="{image_url:height}" alt="{title} {image_url:title} {image_url:desc}" class="small_image img_link" />
                {/case}
            {/exp:switchee}
            {if image_zoom == "y"}</a>{/if} 
        {/exp:stash:set}
    {/cf_{pre_prefix}_images_matrix}

{/exp:channel:entries}

template partials approach:

the standard template:

{embed="_wrapper/_standard"}

{preload_replace:pre_prefix="static"}
{if in_group(1)}{preload_replace:pre_status="open|Draft"}{/if}{preload_replace:pre_status="open"}

{exp:channel:entries channel="ch_static" limit="1" status="{pre_status}" disable="categories|member_data|pagination"}

    {!-- misc stuff --}
    {exp:stash:set scope="site"}
        {stash:entry_id}{entry_id}{/stash:entry_id}
        {stash:title}{title}{/stash:title}
        {stash:og_image}{cf_{pre_prefix}_images_matrix limit="1"}{exp:ce_img:pair src="{image_url:url:max_size}" width="250"}{made}{/exp:ce_img:pair}{/cf_{pre_prefix}_images_matrix}{/stash:og_image}
        {stash:status}{pre_status}{/stash:status}
        {stash:background_image}{cf_{pre_prefix}_background limit="1"}{url:max_size}{/cf_{pre_prefix}_background}{/stash:background_image}
        {stash:color}{sp_color}{/stash:color}
    {/exp:stash:set}

    {!-- preparing the content, but not outputting it yet --}
    {exp:stash:set scope="site" name="main_content" parse_tags="yes" parse_conditionals="yes" output="no"}
        {cf_{pre_prefix}_block_matrix}
            <article class="content_block{if status == 'Draft'} logged_in{/if}">
                {if title}<h1>{title}</h1>{/if}
                {if media AND text}
                    <div class="image">
                        {media}
                    </div>
                    <div class="text">
                        {text}
                    </div>
                {if:else}
                    {text}{media}
                {/if}
            </article><!-- end content_block -->
        {/cf_{pre_prefix}_block_matrix}
        <p class="last_edited hidden"><time datetime="{entry_date format="{sp_datetime_format}"}">Letzte Änderung am {edit_date format="%Y-%m-%d"}</time></p>
    {/exp:stash:set}

    {!-- setting the inline edit links --}
    {exp:stash:set scope="user" name="edit_main_content" parse_tags="yes" parse_conditionals="yes"}
        {if member_group == "1"}<p  class="hide_on_demand"><a class="modalbox_edit" href="/backend/index.php?D=cp&C=content_publish&M=entry_form&channel_id={channel_id}&entry_id={entry_id}" title="Zuerst «Senden» drücken, dann «Schliessen und Neuladen»! Esc um abzubrechen">{title} bearbeiten &uarr;</a></p>{/if}
    {/exp:stash:set}

    {!-- setting the needles --}
    {cf_{pre_prefix}_images_matrix}
        {exp:stash:set name="bild_{row_count}" type="snippet"}
            {if image_zoom == "y"}
                <a class="modalbox_zoom img_link" title="{image_url:title}" href="{exp:ce_img:pair src='{image_url:url:max_size}' width='1200' height='800'}{made}{/exp:ce_img:pair}">
            {/if}
            {exp:switchee variable="{image_size}" parse="inward"}
                {case value="left"}
                    {exp:ce_img:pair src="{image_url:url:max_size}" width="255" allow_scale_larger="yes"}<img src="{made}" class="{image_alignement}" width="{width}" height="{height}" alt="{title} {image_url:title} {image_url:desc} {gv_alt}" />{/exp:ce_img:pair}
                {/case}
                {case value="right"}
                    {exp:ce_img:pair src="{image_url:url:max_size}" width="311" allow_scale_larger="yes"}<img src="{made}" class="{image_alignement}" width="{width}" height="{height}" alt="{title} {image_url:title} {image_url:desc} {gv_alt}" />{/exp:ce_img:pair}
                {/case}
                {case value="full"}
                    {exp:ce_img:pair src="{image_url:url:max_size}" width="600" allow_scale_larger="yes"}<img src="{made}" class="{image_alignement}" width="{width}" height="{height}" alt="{title} {image_url:title} {image_url:desc} {gv_alt}" />{/exp:ce_img:pair}
                {/case}
                {case value="untouched"}
                    <img src="{image_url:url}" width="{image_url:width}" height="{image_url:height}" alt="{title} {image_url:title} {image_url:desc}" class="small_image img_link" />
                {/case}
            {/exp:switchee}
            {if image_zoom == "y"}</a>{/if} 
        {/exp:stash:set}
    {/cf_{pre_prefix}_images_matrix}
{/exp:channel:entries}

here's the wrapper template:

<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="utf-8" />
    {exp:seo_lite entry_id="{exp:stash:get name='entry_id'}" parse="inward"}
    <meta property="og:site_name" content="Café Kairo Lorraine"/>
    <meta property="og:title" content="{exp:stash:get name='title'}" />
    <meta property="og:image" content="{exp:stash:get name='og_image'}" />
    {sp_global_head}
    {exp:stash:get name='color'}

</head>
<body id="{segment_1}">

{embed="_includes/_admin"}

{gv_start}

    <header id="header">
        <h1 id="logo"><a href="{path='/'}" class="hide-text">...</a></h1>
    </header>   

    <section id="content_container">
        <!-- main navigation -->
        <nav id="main_nav">     
            {exp:structure:nav start_from="/" max_depth="1" status="{exp:stash:get name='status'}" css_id="none" parse="inward"}
        </nav><!-- end main_nav -->
        {!-- getting the main content and replacing the needles --}
        {exp:stash:parse process="end"}{exp:stash:get name='main_content'}{/exp:stash:parse}

        {!-- edit links --}         
        {exp:stash:get name='edit_main_content' scope="user"}
    </section><!-- end #content_container -->

    <footer id="footer">
        <p>...</p>  
    </footer><!-- end #footer -->

{gv_before_end}
{embed="_includes/_end"}

<script type="text/javascript">  
    jQuery(function($){
        $.supersized({
            //Background image
            slides  :  [ { image : '{exp:stash:get name='background_image'}' } ]
        });
    }); 
</script>
{gv_end}

so far it works great and also the speed is now better than ever! just one single embed. I am fascinated!

cheers stefan

  • 2
    Try to avoid posting the same question on two separate forums. Most developers are active on both sites so you only make more work for people answering your question twice. – Adrian Macneil Feb 11 '13 at 11:07
  • sorry! I won't do it again :D – outline4 Feb 11 '13 at 12:12
2

You could do this:

{exp:channel:entries ...}

 {cf_images_matrix}
     {exp:stash:set name="image_{row_count}" type="snippet"}
      {exp:ce_img:pair src="{image_url:url}" width="200"}<img src="{made}" width="{width}" height="{height}" alt="{gv_alt}" />{/exp:ce_img:pair}
     {/exp:stash:set}
 {/cf_images_matrix}

 {exp:stash:parse process="end"}
     {cf_textarea}
 {/exp:stash:parse}

{/exp:channel:entries} 
  • Hi mark! this works like a charm! although you have to put process="end" to stash:parse! {exp:stash:parse process="end"} you are a hero! I will make some further test and look if it works with conditionals etc... – outline4 Feb 12 '13 at 11:35
  • I've updated my initial question with a few more examples that I evaluated this morning. I also updated your answer to make it work. Thanks A LOT for pointing me into the right direction! – outline4 Feb 12 '13 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.