I'm trying to make my press release pages a little more fool-proof so instead of leaving the formatting of the location and date to the user I want to create a location matrix field (they type the city name and choose a state from a drop down menu; states MUST be spelled out hence the dropdown field) and prepend the output of this to the wygwam field that contains the press release content. I'll also add the date from the entry_date field to this. The output will eventually look something like this:

location, state - month day, year - begin press release...

I can set the stash without any problems and even output it on its own but I'm not sure how I could go about prepending it to the Wygwam content. In the past I've done this with MX Jumper but it required the addition of some random content at the beginning of the press release that could be swapped out. I'm hoping I can do this with Stash without the need for any extra content in the press release content field. Any suggestions on how this might work?

Update with template code:

{exp:channel:entries channel="press_releases"}
    {exp:stash:set name="pr-date-loc"}
        {press_release-location}<strong>{pr-city}, {pr-state} &mdash; {entry_date format="%F %j, %Y"} &mdash; </strong>{/press_release-location}

{exp:channel:entries channel="press_releases"}
    {exp:stash:prepend name="pr-date-loc"}
  • You can use {exp:stash:prepend name="my_var"}...{/exp:stash:prepend} to prepend the enclosed value to an existing Stash variable. Or do you mean something else? If so, please update your question with the template code you are using. Commented Jan 8, 2013 at 19:18
  • @MarkCroxton I've added the relevant template code above. {press_release-location} is my matrix field and {press_release-content} is my Wygwam field. I just want to ensure {press_release-location} starts inside the opening paragraph tag of {press_release-content} so it conforms to standard practices of press releases. Commented Jan 8, 2013 at 19:37
  • I don't know if I'm missing the obvious, but wouldn't removing the first entries tag and adding the matrix tag above the wygwam field work?
    – Siebird
    Commented Jan 8, 2013 at 20:07
  • I should have also noted that I'm using v2.1.0 and not the 2.3.5 beta as this is for a production site. If v2.3.5 does this any better then I might consider it but according to the docs v2.1.0 should wok just fine. Commented Jan 8, 2013 at 20:51
  • @Siebird no, because Wygwam outputs formatted HTML, it begins with an opening <p> tag. If I did what you suggest it would place the location and date above the press release content, not inline with it. I'm hoping I can use stash to inject this matrix output after the opening <p> tag that Wygwam outputs, preferably without the need for extra content in the Wygwam field itself. Commented Jan 8, 2013 at 22:17

1 Answer 1


You can use the filter parameter to filter the output of a Stashed variable, in this case to remove the opening and closing <p> tags. You will need the Development version of Stash (currently v2.3.6) for the following to work:

{!-- capture the values --}
{exp:channel:entries channel="press_releases"}
    {exp:stash:set parse_tags="yes"}
        {stash:pr-date-loc}{press_release-location}<strong>{pr-city}, {pr-state} &mdash; {entry_date format="%F %j, %Y"} &mdash; </strong>{/press_release-location}{/stash:pr-date-loc}

{!-- output the values, if in the same template that you set the variables --}
{exp:stash:get name="pr-date-loc" process="end"}
{exp:stash:get name="pr-content" filter="#(?m)^<p>(.*)</p>$#" process="end"}

{!-- output the values if in an EE or Stash embed --}
{exp:stash:get name="pr-date-loc"}
{exp:stash:get name="pr-content" filter="#(?m)^<p>(.*)</p>$#"}
  • Note: when upgrading to 2.3.6, don't forget to install the Stash extension! Frequently happens. Commented Jan 9, 2013 at 10:20
  • Alternative regex to match any opening or closing html tag: #(?m)^<[a-zA-Z][a-zA-Z0-9]*\b[^>]*>(.*)</[a-zA-Z][a-zA-Z0-9]*\b[^>]*>$# Commented Jan 9, 2013 at 10:32
  • I'm not sure if swearing is allowed but fcuk you're a switched on fcucker Commented Jan 9, 2013 at 10:37
  • I'm doing a crash course in RegEx right now but so far the above only half works. The stash tags are outputting correctly but the pr-date-loc variable is being wrapped in its own p tag and the pr-content variable still contains its opening p tag. Commented Jan 9, 2013 at 15:45
  • 1
    Could be you're getting whitespace or line breaks at the beginning of the WYGWAM content. You can eliminate that when you SET the stash variables by adding the parameter trim="yes" to the {exp:stash:set} tag Commented Jan 9, 2013 at 17:00

Your Answer

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

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