Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-06-08 12:56:32
- Ace of Dubs
- Member

- Registered: 2006-04-17
- Posts: 446
TXP Tags inside CSS docs
WOuld it be possible to output data from my custom fields right into my CSS?
For example, let’s say I am doing a discography and all the releases are numbered. I know that I can make a custom field called “Release #” and then have the flexibility to put
<txp:custom_field name="Release #" />
Wherever I want it to show up.
My question is…is it possible to also put this tag into my CSS document? I am trying to slap different images into each class and instead of 100 lines of CSS code, I wonder if this would work…
#<txp:custom_field name="Release #" /> {background: #000 url(img/<txp:custom_field name="Release #" />.gif no-repeat;)
My first attempts have not been successful so I am guessing that TxP only parses html. If that’s the case, then we can move this thread to Feature Ideas, as I think it would make a powerful and elegant solution for a lot of on-the-fly CSS styling.
With this system in place, my clients simply enter the release number and that gets handed off to the html and related css, no fuss no muss…
Last edited by Ace of Dubs (2006-06-08 12:58:45)
Offline
#2 2006-06-08 15:27:03
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: TXP Tags inside CSS docs
Nope, CSS isn’t parsed for tags. A plugin could easily do this though.
Offline
#3 2006-06-08 16:49:01
- Ace of Dubs
- Member

- Registered: 2006-04-17
- Posts: 446
Re: TXP Tags inside CSS docs
That would rock hardcore!
Anyone up for this “easy” challenge? Man I really need to stop being such a punk and learn PHP already …
Offline
#4 2006-06-08 16:54:48
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: TXP Tags inside CSS docs
I’ve added this to the Plugin Requests thread. :)
Offline
#5 2006-06-08 17:44:10
- Ace of Dubs
- Member

- Registered: 2006-04-17
- Posts: 446
Re: TXP Tags inside CSS docs
Sweet! :D
Hope it comes out soon. In the meantime, its good old search/replace for me..what fun! :(
Offline
Re: TXP Tags inside CSS docs
Are you looking for embedded CSS? Maybe I’m being thick (seems to be my thing today), but that seems to be the only way to get the custom fields from the articles to parse… Unless I’m being dumb? Other plugin devs, thoughts?
Uhm, yeah, I’m willing to take this on.
Offline
#7 2006-06-08 19:03:30
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: TXP Tags inside CSS docs
Ah yeah, wasn’t thinking that through. It could parse for tags, but only general ones, not articles, comments, etc, because those tags only work after an article page tag is encountered, for example.
Offline
Re: TXP Tags inside CSS docs
If I’m not mistaken, mrdale had kind of a solution to this or thereabouts. See it.
Offline
#9 2006-06-09 01:01:53
- Ace of Dubs
- Member

- Registered: 2006-04-17
- Posts: 446
Re: TXP Tags inside CSS docs
That is a useful thread there Destry…not what I am looking for though.
I would like to have my CSS dynamically call in images based on what my client types into the custom fields.
I would also benture to say that it would be pretty nifty to add some conditional magic to the plugin,
For example: if the field calls for an image that does not exist, rather than show the broken link, a default image is shown in its place. I imagine the logic to be like this
<if txp:custom_field name="Release #">
<txp:custom_field name="Release #" />
<else txp:custom_field name="Default #" />
</if txp:custom_field name="Release #">
I know I butchered the syntax above, but I think you get the picture
Last edited by Ace of Dubs (2006-06-09 01:02:59)
Offline
#10 2006-06-09 01:39:58
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: TXP Tags inside CSS docs
I thought about it some more, and it would be possible with a plugin if you also passed the current article’s id# to the stylesheet.
Offline
Re: TXP Tags inside CSS docs
Yeah, that was the only thing that was coming to mine when I was thinking this over. I suppose I’ll give it a shot like that.
Offline
Re: TXP Tags inside CSS docs
Can’t you just insert into the template something of this kind
<txp:if_custom_field name="Release #">
<div style="background-image: url(img/<txp:custom_field name="Release #" />.gif)"></div>
<txp:else />
<div style="background-image: url(img/no-pic-or-whatever.gif)"></div>
</txp:if_custom_field>
Basically separating content from presentation. It seems like you are trying to use CSS for content.
Plugin Composer — admin plugin to write your own plugins
Offline