Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#41 2011-04-11 07:15:10

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

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

+1
I’m not very happy with those <p></p>containers …

Is it possible to modify the way textile act ???
(As an option, for compatibility)

Offline

#42 2011-04-11 08:54:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,723
Website

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

jpdupont wrote:

Is it possible to modify the way textile act ???

Your best place to find out that sort of thing is on the Textile repo. The conversations on the Issues tracker might give you some ideas. The various experimental dev branches add support for defining your own block level elements so I guess, in theory, you could find some way to kill them.

Last edited by Bloke (2011-04-11 08:54:33)


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

#43 2011-04-11 15:15:39

jcd
Member
Registered: 2010-04-15
Posts: 12

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

jakob wrote:

How about using pax_grep or a snippet of php in your smd_macro to remove the <p> and </p> from the output as outline here? That would happen server-side prior to code output.

Thanks jakob, but as far as I understand there is nothing you can do from within a macro to influence the surrounding <p> tags added by Textile. If I used this strategy outside of the macro this would probably work, but adding a space in front of the macro tag inside of the article seems a lot easier for the client.

Offline

#44 2011-04-11 22:18:48

els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

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

jcd wrote:

Thanks jakob, but as far as I understand there is nothing you can do from within a macro to influence the surrounding <p> tags added by Textile.

You could do something like this in your article form I guess. Assuming the macro output is wrapped in <ul> tags (don’t know pax_grep so this is with rah_replace):

<txp:rah_replace from="<p><ul>,</ul></p>" to="<ul>,</ul>"><txp:body /></txp:rah_replace>

Offline

#45 2011-04-22 06:52:41

phuture303
Member
Registered: 2008-09-14
Posts: 127

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

Stef, just solved my first tiny steps with this plugin. It is FUCKING BRILLIANT! Wonderful, I just made the output of image galleries (in combination with a left-sided dropdown custom field of the existing image categories) the most easy thing I’ve ever seen :-)

End Els, thanks for the tip with rah_replace for deleting the <p>-tags surrounding the gallery. Just for the noobs like I am: if you need your <ul>-tag with a class or an id, then use:

<txp:rah_replace from="<p><ul,</ul></p>" to="<ul,</ul>"><txp:body /></txp:rah_replace> just without the closing braket at the opening <ul>-tag.

Perfect, this forum made my day. Again. Textpattern rocks – and you pros do, too.

David

Offline

#46 2011-05-04 13:00:02

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,723
Website

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

By way of an example macro suite, here’s my attempt at an interface to jQuery Tools tabs. Save the link and you can import them directly into smd_macro.

On your tabbable page(s), just include the jQuery Tools .js file as normal and ensure you have obtained a reference to the API using something like this code:

<script type="text/javascript">
   var api = jQuery("#wrapper").data("scrollable");
</script>

where wrapper is the DOM element that contains your tab panes. You can use a different variable name other than api if you wish, just remember to tell the macros what you’ve called it via the api_ref attribute (or edit the defaults in the macro definitions).

You or your clients can then use the following tags to present tab navigation links:

  • <txp:prev_tab /> : jump to the previous tab (will wrap if permitted). Attributes:
    • text = the text label. Default: « Previous
    • class = the class to apply to the anchor link. Default: learnmore
    • api_ref = the name of your javascript api variable. Default: api
  • <txp:next_tab /> : jump to the next tab (will wrap if permitted). Same attributes as above (text = Next »)
  • <txp:goto_tab /> : jump to the designated tab number. Attributes:
    • number = the tab to jump to, indexed from 1. Default: 1
    • class = the class to apply to the anchor link. Default: learnmore
    • api_ref = the name of your javascript api variable. Default: api
  • <txp:tab_nav /> : display a Goooogle style nav bar. Attributes:
    • tabs = the number of tabs in your set. Default: 1
    • class = the class to apply to the navigation wrapper div. Default: tabnav
    • breakclass = the class to apply to each anchor link. Default: learnmore
    • prev_text = the text label for the ‘prev’ link. Default: Previous
    • next_text = the text label for the ‘next’ link. Default: Next
    • api_ref = the name of your javascript api variable. Default: api

If you’re using MLP you can probably edit the macros to use ##snippet## syntax (untested).

Note that the macros are totally unsupported, they’re just available as examples for you to tweak and play around with. Hope they’re useful to someone.


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

#47 2011-05-08 22:08:57

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,937
Website

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

How might I test whether a custom smd_macro attribute has been specified (as opposed to empty) within the macro code, for example using smd_if? As soon as I use txp:if_variable, I define a txpvar, even if it is empty, so I can’t do a three way test with it.

Use case example: a tag that outputs a figure tag with attributes id and caption:

  • if the attribute caption is not specified (=undefined), then output the image’s own caption
  • if the attribute caption="custom text", i.e. is specified, override and use the custom caption
  • if the attribute caption="", i.e. is explicitly set to empty (=isempty) do not show a caption
I tried smd_if with field="phpvar:caption" and field="phpvar:lAtts[caption]" but to no avail:
<figure>
  <txp:image id="{img_id}" />
  <txp:smd_if field="phpvar:caption" operator="defined">
    <txp:smd_if field="NULL" operator="isempty" value="{caption}">
    <txp:else />
      <figcaption>{caption}</figcaption>
    </txp:smd_if>
  <txp:else />
    <figcaption><txp:image_info id="{img_id}" type="caption" /></figcaption>
  </txp:smd_if>
</figure>

Last edited by jakob (2011-05-08 22:14:11)


TXP Builders – finely-crafted code, design and txp

Offline

#48 2011-05-09 00:55:55

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,723
Website

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

jakob wrote:

How might I test whether a custom smd_macro attribute has been specified (as opposed to empty) within the macro code

Along with the problem of container macros, this scenario — the detection of whether an attribute is set or not — did occur to me as I was writing the plugin but I never came up with a satisfactory solution. There are times when you simply want to completely omit an attribute inside your macro — for example, whan an empty macro attribute is passed in and you want the TXP tag inside to take on its defaults. Currently there’s no neat way of doing that, which is a shame.

To further compound things, the $atts array doesn’t behave as you’d expect, probably because the function is actually not a real function. Certainly if you simply try to dmp($atts); you get nothing back which, I suspect, is due to the way the parser works. Or that it’s late and my brain’s slowly giving up. You can get funky with PHP5’s new ReflectionFunction() but it gets messy very quickly inside a php block.

In your case, smd_if can indeed come to the rescue and do a 3-way test but you have to be cunning. Give the macro’s caption attribute a default value that you will never reasonably expect people to type — I’ve chosen SMD_NONE here. Then you can proceed as follows:

<figure>
  <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>

How’s that?

Last edited by Bloke (2011-05-09 00:57:41)


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

#49 2011-05-09 06:50:44

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,937
Website

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

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:

That gives you a tag that behaves as follows:

  • <txp:figure id=123" caption="My custom caption" /> – inserts image 123 with an HTML5 figcaption entitled “My custom caption”.
  • <txp:figure id=123" /> – inserts image 123 with an HTML5 figcaption with whatever is set in your images caption field.
  • <txp:figure id=123" caption="" /> – inserts image 123 with an HTML5 figure and no figcaption.

Last edited by jakob (2011-05-09 06:55:11)


TXP Builders – finely-crafted code, design and txp

Offline

#50 2011-09-05 14:25:14

stephan
Plugin Author
From: Bochum, Germany
Registered: 2004-07-26
Posts: 196
Website

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

Tried it, loved it. But one thing I really need your help with:
I have a macro with several attributes and I do not wish to type the entire thing in each time. How can I integrate the marco in the write tab (e.g. insert the specific macro at the push of a button so all I would have to do is fill in the values of the attributes)?

The idea is to create a review rating table with a star rating via macro and the individual ratings in five categories would be the attributes (as the name of the object under review).


Yoko for Textpattern – A free blog themeMinimum Theme – If all you want to do is write.
Note: I am currently not actively using Textpattern, so I am not in the forums very often

Offline

Board footer

Powered by FluxBB