Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How do I change the processing order of shortcodes and wrapper tags?
Over in another thread about post-processing the body field before saving I mentioned a use case of splitting the body into sections. I haven’t (yet) implemented that as plugin that acts on article_submit so currently I use this as a wrapper plugin around txp:body that takes the html produced by textile and splits it into sections, i.e.:
<txp:jcr_sectionize>
<txp:body />
</txp:jcr_sectionize>
This is the simplified idea:
User input as regular Textile in the body field. The user doesn’t need to concern themselves with presentational markup:
h2. My title
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.
h2. Another title
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren
and so on. Regular textiled html output:
<h2>My title</h2>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.</p>
<h2>Another title</h2>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren</p>
The jcr_sectionize plugin splits that into sections (using DOMdocument to split into nodes, insert the wrappers and reoutput as html) that I can format in CSS into two columns with sticky headers. This is the post-processed html output:
<section class="body-section">
<h2>My title</h2>
<div class="body-text">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.</p>
</div>
</section>
<section class="body-section">
<h2>Another title</h2>
<div class="body-text">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.</p>
</div>
</section>
So far so good. That all works fine. With a smattering of css, you get sticky section titles on the left and body text on the right in a roughly 1/3-2/3 column layout. Putting a shortcode embed inside body text blocks is no problem.
Now I want to add a shortcode to embed some other content that spans both columns, for example a location map or an image gallery. I currently have my shortcode like this so that it breaks out of the current text block, creates a new section of its own, and then goes back to the text flow:
</div>
</section>
<section class="body-section embed-item">
<!-- the shortcode does its stuff here -->
</section>
<section class="body-section">
<div class="body-text">
The problem is my wrapper plugin ruins the code produced by the shortcode, presumably because it’s not producing clean nodes.
My question is, can I control the processing order of the wrapper plugin and shortcode in the body field. I tried something like this (simplified version).
<txp:jcr_sectionize[1]>
<txp:body />
</txp:jcr_sectionize>
and then in the body field of the article:
… text …
<txp::my_shortcode[2] />
… more text …
… but no luck.
Is this possible? Is there perhaps a better way? Would post-processing the body_html on article_submit (instead of as a wrapper tag) get around this as shortcodes are not translated into html output in the body_html field?
TXP Builders – finely-crafted code, design and txp
Offline
Re: How do I change the processing order of shortcodes and wrapper tags?
Current workaround: I expanded on the plugin to also split cleanly at a certain class, i.e. embed-item that I should be able to use in different txp::shortcodes if I want to break out of the columnized layout.
TXP Builders – finely-crafted code, design and txp
Offline
Re: How do I change the processing order of shortcodes and wrapper tags?
I wonder if adding the breakby attribute to the plugin can do the job. It will however limit as to where the gallery/map/video/whatever will appear and might even produce unwanted layout results.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#4 Today 17:51:32
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,320
Re: How do I change the processing order of shortcodes and wrapper tags?
Reminds me of an ancient plugin: jcb_columnize (still available for download.)
from its help text:
Modes of operation
1 Split by Tag
This is the default mode for the plugin. Arguments specific to this mode are:splitontag What tag to use as breaking points for the columns. Defaults to ‘p’. Do not include any angle brackets- only the name of the tag.
columns The number of columns to generate. Two or three seem to work best with shorter articles. Defaults to 2.
minsplit This is a minimum number of break points needed to columnize. Defaults to columns. This is a little buggy.
2 Split by String
This mode allows for creating column divisions wherever a selected string occurs. To activate this mode, set the attribute splitonstring equal to something other than “”.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: How do I change the processing order of shortcodes and wrapper tags?
jakob wrote #342948:
My question is, can I control the processing order of the wrapper plugin and shortcode in the body field. I tried something like this (simplified version).
<txp:jcr_sectionize[1]>...and then in the body field of the article:
… <txp::my_shortcode[2] /> …...
Not this way. Recall that the bracket syntax can only alter the processing order of siblings, i.e. tags that are direct children of a common parent tag. Here, <txp::my_shortcode /> is inside <txp:jcr_sectionize />, not its sibling.
Is this possible? Is there perhaps a better way? Would post-processing the body_html on article_submit (instead of as a wrapper tag) get around this as shortcodes are not translated into html output in the
body_htmlfield?
Processing on submit is clearly better, since it is done only once, not on each page visit. If you can, I would advice this way. Otherwise, provided your plugin handles it nicely, you can try postponing shortcodes inside the body to the second pass:
...
<txp:hide process="2">
<txp::my_shortcode />
</txp:hide>
...
There should certainly be a less hacky solution, challenge open.
Online