7

Like most people, I was using NSM Transplant in tandem with Matrix to have {image_1} etc within a WYSIWYG field like so http://vimeo.com/18661374

I've managed to achieve the same thing using a template partials approach, however, I'm working on a site just now that's been an upgrade from EE1 (which used LG Replace) and I have no desire to refactor the templates to template partials.

Is there a way I could achieve the same thing in the Vimeo video using Stash?

3 Answers 3

7

Try my answer on this question - works for me on a single template:

EE Code within channel entries

{exp:stash:set name="shortcode_inside_field" type="snippet"}
    <p>Hi there! It's important to set type="snippet" so that {shortcode_inside_field} will get automatically replaced with this sentence by the stash:parse tag later on.</p>
    ... now run all kinds of complicated EE tags here to generate the content of the shortcode (be sure to add parse_tags="yes") ....
{/exp:stash:set}

{exp:channel:entries}
    {exp:stash:parse process="end"}
        {custom_field_containing_shortcodes}                
    {/exp:stash:parse}
{/exp:channel:entries}

... Also, make sure you're not using EE 2.5.3, since there's a bug affecting curly braces inside content entries (there's a hotfix for it if you can't upgrade to 2.5.5).

EDIT TO INCLUDE PROPER ANSWER!!

I've tested this code with Matrix, and it works for me:

    {exp:channel:entries}

        {gallery_matrix}
            {exp:stash:set type="snippet"}
                {stash:image_{row_count}}
                    <img src="{src}">
                {/stash:image_{row_count}}
            {/exp:stash:set}
        {/gallery_matrix}

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

    {/exp:channel:entries}

There are two ways of doing this with Stash - either using that _{row_count} appendage, or using Stash's context parameter. Purists may prefer the latter, personally I prefer the former...

3
  • upgraded to 2.5.5 and changed code to {exp:stash:set name="image_{row_count}" type="snippet" parse_tags="yes"} <p>Hi there! It's important to set type="snippet" so that will get automatically replaced with this sentence by the stash:parse tag later on.</p> {/exp:stash:set} {exp:stash:parse process="end"} {cf_content_body} {/exp:stash:parse} would have expected {image_1} to be replaced with the paragraph tag? Jan 14, 2013 at 0:25
  • Ah, sorry forgot about the matrix... will edit my answer with a working tested version Jan 14, 2013 at 0:50
  • sweet - that works like a charm :-) unfortunately it doesn't solve this issue expressionengine.stackexchange.com/questions/1990/… - which I had hoped a move to Stash would resolve - seems to do the same thing as NSM Transplant but I'll definitely be using this on future builds. Jan 14, 2013 at 1:56
2

Check out this article by @tyssen: http://www.tyssendesign.com.au/articles/cms/more-stash-examples/ The 'shortcodes with Stash' examples should get you there.

There's also this thread on Devot-ee: http://devot-ee.com/add-ons/support/stash/viewthread/3013 which tries to solve a similar NSM transplant solution.

2
  • Thanks Erwin, I saw those. The Devot-ee link works when using template partials but not within a single template (that I could get working anyway). It just outputs {image_1} within the content - according to CE Image, the path is empty (I think probably a parse order issue). Jan 13, 2013 at 22:54
  • Yeah it's parse order. Snippets are parsed early, which is why they work in the embed as the parent template set the snippets. In your case, by the time the vars are added to the snippets array, they've already been and gone in the template rendering process. Jan 13, 2013 at 23:11
1

This is really an addendum to James' answer above; you can do the same thing without needing to use post-processing - this may overcome the problem of previewing within BWF that you encountered here: weird CE Image & Better Workflow issue

{exp:stash:parse parse_depth="2"}
    {exp:channel:entries}
        {gallery_matrix}
            {exp:stash:set type="snippet"}
                {stash:image_{row_count}}
                    <img src="{src}">
                {/stash:image_{row_count}}
            {/exp:stash:set}
        {/gallery_matrix}
        {exp:stash:set name="content_body"}{cf_content_body}{/exp:stash:set}
    {/exp:channel:entries}
{/exp:stash:parse}

{exp:stash:get name="content_body" parse_vars="yes"}
2
  • this approach does work but doesn't resolve the BWF issue. The BWF issue would have been a nice to resolve but this is more useful to be honest. Jan 14, 2013 at 22:43
  • Would parse_depth="2" not incur a similar kind of overhead as process="end"? Jan 19, 2013 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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