Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#73 2012-12-01 18:09:36

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

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

Hola Jorge

Some typos in your examples above (also in the TXP Tips article?).

Macro Definition Remove the /> after <txp:image id=’{img_id}’

CSS Closing brackets required in these declarations:

.photo {

and in

.photo .right {

Guessing you were converting SCSS or LESS to CSS?

Otherwise, truly excellent article!

Last edited by joebaich (2012-12-01 18:12:08)

Offline

#74 2012-12-01 18:31:13

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

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

Thanks Joe:

I adapted it on the fly from my personal use version (a bit more complicated) so it is easy to introduce mistakes.

This weekend on mobile only, the monday will edit the post to ad your corrections. thanks


<txp:rocks/>

Offline

#75 2013-07-12 16:31:14

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

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

I created a form “datei-download”:

<a href="<txp:file_download_link />"><txp:file_download_name title="1" /></a> (<span class="dateiformat"><txp:php>echo pathinfo(parse('<txp:file_download_name />'), PATHINFO_EXTENSION);</txp:php></span>, <span class="eng"><txp:rah_replace delimiter="|" from=".|,|kB|MB" to=" |.| <abbr>KB</abbr>| <abbr>MB</abbr>"><txp:file_download_size decimals="0" /></txp:rah_replace></span>)

In the following context it works fine:

<txp:file_download id="id-number" form="datei-download" />

But, in a macro like the following, the PHP part for the file extension is not parsed:

Macro definition: <txp:file_download id="{datei}" form="datei-download" /> (“datei” = the id number).

Any idea why?

Offline

#76 2013-07-12 19:00:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,436
Website GitHub

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

GugUser wrote:

Macro definition: <txp:file_download id="{datei}" form="datei-download" />

Must admit I’ve never tried overriding a built-in function with a macro. I’m surprised it worked at all and didn’t give you a parser error. Long shot: does it work if you rename the macro?

EDIT: failing that, it may be the parse() call that’s not working for some reason. Perhaps because of the quotes-in-quotes. My macro parser isn’t very smart. You could try:

<txp:php>echo pathinfo(file_download_name(array()), PATHINFO_EXTENSION);</txp:php>

Last edited by Bloke (2013-07-12 19:06: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

#77 2013-07-12 19:22:12

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

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

Thank you, Bloke.

I tried with file_download_name(array()) too, but it didn’t work.

None of the three suggestions helps.

Why you wrote “overriding a built-in function with a macro”? I don’t understand this.

Offline

#78 2013-07-12 19:24:27

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

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

One more strange thing: In browsers, the file extension isn’t shown, but in the NetNewsWire news reader …

Offline

#79 2013-07-12 19:39:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,436
Website GitHub

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

GugUser wrote:

Why you wrote “overriding a built-in function with a macro”? I don’t understand this.

Because, according to what you wrote in the post above, your macro definition is called “file_download” which is the name of a built-in tag. Which maps to the file_download() function. Having two functions with the same name is illegal in PHP so perhaps the only reason it doesn’t error is because of the late-binding of the macro (or because your site is Live and the error is getting swallowed).

It might not be that at all, but before we investigate further, I’d eliminate the duplicate tag name by renaming the macro to something different (preferably with a gug_ prefix or something).


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

#80 2013-07-12 19:42:28

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

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

No, no, this isn’t the tag name, it’s the macro definition. The tag name is “datei”, so the user can put the ID in <txp:datei id="1" />. This works fine, only the PHP thing don’t work.

Last edited by GugUser (2013-07-12 19:44:49)

Offline

#81 2013-07-12 19:46:51

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,436
Website GitHub

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

GugUser wrote:

No, no, this isn’t the tag name, it’s the macro definition.

Gotcha, sorry. I was being dim.


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

#82 2013-07-12 19:55:57

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,436
Website GitHub

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

GugUser

Weird, I just made a macro called datei with one attribute (id) which mapped to the replacement datei, put the definition of the macro in as you had it, with the form datei-download copy and pasted from your post above… and it worked. I got (txt, 17 Kb) displayed in the browser when I did <txp:datei id="21" /> inside an article.

I wonder why yours is not parsed. It’s not the value of your Allow PHP in Articles / Forms / Pages settings in Advanced Prefs?

EDIT: no it can’t be. Because it works outside the macro. Hmmm.

Last edited by Bloke (2013-07-12 20:00:08)


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

#83 2013-07-12 20:01:21

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

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

Bloke wrote:

I wonder why yours is not parsed. It’s not the value of your Allow PHP in Articles / Forms / Pages settings in Advanced Prefs?

It’s all in “yes”.

Offline

#84 2013-07-13 04:48:50

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

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

I found the reason for the problem. It has to do with the limited privileges of the “staff writer”. If an “staff writer” puts the smd_macro tag <txp:datei id="1" /> in an article, then the PHP in the form “datei-download” is not parsed, although is no PHP directly in the article. If I change the privileges of the author to “publisher”, then it works.

Unfortunately, this is not what I need. I need a solution for the “staff writer”. Any idea?

Last edited by GugUser (2013-07-13 04:50:33)

Offline

Board footer

Powered by FluxBB