Textpattern CMS support forum

You are not logged in. Register | Login | Help

#131 2017-11-13 15:44:53

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,617
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

jakob wrote #245939:

Cool! and cunning. That works!

BTW: for those, like me, who may not initially understand the logic, it is ESSENTIAL to insert SMD_NONE (or a non-word of your choice) as the default value in the attributes section above the code:

I am checking an amended version of this macro out but it seems to be chocking after it parses the image tag

In the macro I have

<figure itemscope itemtype="http://schema.org/ImageObject" class="{class}">
<txp:image id="{img_id}" />
<txp:smd_if field="{caption}" operator="eq" value="SMD_NONE">
<figcaption><txp:image_info id="{img_id}"> type="caption" /></figcaption>
<txp:else />
<txp:smd_if field="NULL" operator="eq" value="{caption}">
<txp:else />
<figcaption>{caption}</figcaption>
</txp:smd_if>
</txp:smd_if>
</figure>

The tag I use in the write tab is

<txp:figure id="58" caption="my caption" class="grid_9"  />

the parsed code is

<figure itemtype="http://schema.org/ImageObject" class="grid_9">
<img src="http://respublika.neme.org/images/58.jpg" alt="" width="350" height="240" />

There is no figcaption and the closing figure.

Can anyone spot what I am doing wrong? I am using the 0.41 version of the plugin.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Online

#132 2017-11-13 15:52:48

jpdupont
Member
From: Virton (BE)
Registered: 2004-10-01
Posts: 710
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

A > to much —> <txp:image_info id="{img_id}" type="caption" /> ?

See the bad syntax highlighting …

Last edited by jpdupont (2017-11-13 15:54:10)

Offline

#133 2017-11-13 16:09:32

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,617
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

Thanks so much jp… I was so blind to it… It’s now working as intended


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Online

#134 2017-12-13 13:45:30

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,617
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

Well… a month later and there is something wrong which breaks the page:)

Here is a screenshot of the macro:

Here is the code:

<figure itemscope itemtype="http://schema.org/ImageObject" class="{class}">
<txp:image id="{img_id}" />
<txp:smd_if field="{caption}" operator="eq" value="SMD_NONE">
<figcaption><txp:image_info id="{img_id}" type="caption" /></figcaption>
<txp:else />
<txp:smd_if field="NULL" operator="eq" value="{caption}">
<txp:else />
<figcaption>{caption}</figcaption>
</txp:smd_if>
</txp:smd_if>
</figure>

and here is the front end error on this page.:

Tag error: <txp:smd_if field="ONR Nicosia Wall 1" operator="eq" value="SMD_NONE"> ->  Textpattern Notice: unregistered_tag while parsing form None on page artworks

ps. This is the code used in the page: <txp:figure id="104" class="grid_6 clearleft" caption="ONR Nicosia Wall 1" />

ps2. I am testing the page which has about 35 figures.

After deleting all except the first one (code above), all is working and also works when including the 2nd one. When I add the 3rd, <txp:figure id="126" class="grid_6" caption="Moved Wall by Adriana Frias Gon&ccedil;alves, Ana Sofia Sousa Soares, Ana Filipa Santos Pimenta, and Nico Carpentier" />, the page breaks… Does anyone have any idea?

Last edited by colak (2017-12-13 14:19:41)


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Online

#135 2017-12-13 14:23:24

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 2,916
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

I get a syntax error, unexpected 's' (T_STRING) on that page.

The unregistered tag probably just means this is missing from the beginning of the “Begin public code” part of the smd_if plugin:

if (class_exists('\Textpattern\Tag\Registry')) {
	    Txp::get('\Textpattern\Tag\Registry')
		    ->register('smd_if')
	;
}

Aside from the error, do you still get the correct output?

EDIT: What happens if you just specify caption="Nicosia Wall 1" and leave out the ONR? I wonder if it’s processing “ON” somehow. Try also ç instead of the entity with & and ; in it.


TXP Builders – finely-crafted code, design and txp

Offline

#136 2017-12-13 14:29:21

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,617
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

jakob wrote #308296:

I get a syntax error, unexpected 's' (T_STRING) on that page.

The unregistered tag probably just means this is missing from the beginning of the “Begin public code” part of the smd_if plugin:

if (class_exists('\Textpattern\Tag\Registry')) {....

Aside from the error, do you still get the correct output?

Even with ‘registering the tag’, the whole page chokes although nothing else is revealed when setting the site on debug mode. I have some more info on ps2 above.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Online

#137 2017-12-13 14:38:55

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 2,916
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

I added a note too about ps2. Was just wondering whether smd_if is trying to process some special characters or words in the field attribute (i.e. the caption text) – like ON or &, or ; or , – and that that might be triggering the problem.


TXP Builders – finely-crafted code, design and txp

Offline

#138 2017-12-13 15:33:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,303
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

Weird, but testing a caption like that as a field is prone to breakage since it doesn’t escape the field name. You might have more luck with:

<txp:smd_if field="SMD_NONE" operator="eq" value="{caption}">

Or try escaping the content with :ESC or :ESCALL:

<txp:smd_if field="{caption}:ESCALL" operator="eq" value="SMD_NONE">

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#139 2017-12-14 04:53:04

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,617
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

I think I got it. I had No Land's Man in a caption. The apostrophe was chocking the page even with :ESC or :ESCALL. I changed it to No Land&#8217;s Man and all seems to be working fine.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Online

#140 2018-02-28 14:04:27

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 3,754
Website

Re: smd_macro: Create custom virtual Txp tags that do stuff

I have my first macro, a popular one, I’m guessing. But the caption is not outputting. Instead I’m just getting “SMD_NONE”. Following is the macro.

Attributes table.

Name Default Replacement name
id img_id
caption SMD_NONE caption
class SMD_NONE class_value

Macro markup:

<figure<txp:smd_if field="{class}" operator="eq" value="SMD_NONE"><txp:else /> class="{class_value}"</txp:smd_if>>
   <txp:image id="{img_id}" />
   <txp:smd_if field="{caption}" operator="eq" value="SMD_NONE">
       <figcaption><txp:image_info id="{img_id}" type="caption" /></figcaption>
   <txp:else />
       <txp:smd_if field="NULL" operator="eq" value="{caption}">
       <txp:else />
           <figcaption>{caption}</figcaption>
       </txp:smd_if>
   </txp:smd_if>
</figure>

It outputs the image fine, uses the class as desired, but the caption is not the one in the caption field, which reads, “An example of endnotes and back-links employed in Wikipedia.”.

I must be overlooking a typo or something?

Update: Code above is now correct and working. (Thanks, Bloke.) Use it safely and well!

Last edited by Destry (2018-02-28 14:16:33)

Offline

Board footer

Powered by FluxBB