Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
New Tag for resources URL
After reading this interesting tip on increasing your site’s performance using different (sub-)domain to serve static files I think it may be nice to add a new tag that could be used to represent an optional resource URL.
Right now we have <txp:site_url />
so would it make sense to add <txp:site_resources_url />
that I can configure in my extended settings if I desire to do so?
I must admit that I did not fully grasp what ihu does and how powerful it is. However it strikes me as being slightly breaking the paradigm of full control and flexibility in the forms.
define('ihu', 'http://static1.example.com/')
Maybe there is another way to tell the magic ihu which types of files to serve from the static URL? I’d like to have more than just my images served from this URL (also JS, CSS, movies, flash files, etc.).
Yoko for Textpattern – A free blog theme • Minimum 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
Re: New Tag for resources URL
Hi Stephan,
what I do is this.
In my config.php file I’ve :
$txpcfg['static_media_url'] = '/static';
(you could set it to $txpcfg['static_media_url'] = 'http://static.example.com';
)
Then, I’ve a form named “vars” loaded at the very top of my page templates, and there, I’ve this code:
<txp:variable
name="static_media_url"
value='<txp:php>echo $GLOBALS["txpcfg"]["static_media_url"];</txp:php>'
/>
That creates a TXP variable named “static_media_url”, that you can then use like this <txp:variable name="static_media_url" />
.
Offline
Re: New Tag for resources URL
Using Julián’s example you could also use the ihu constant too:
<txp:variable name="static_media_url" value='<txp:php> echo ihu; </txp:php>' />
stephan wrote:
I must admit that I did not fully grasp what ihu does and how powerful it is.
It’s used when building URLs that point to the images (that’s it, nothing more or less, just alternative URL), and plugins can rely to it if the developer wants to do so (for example custom CDN integration).
However it strikes me as being slightly breaking the paradigm of full control and flexibility in the forms.
The override configuration (which is what most sites won’t be using at all) is placed to config file instead of to the database, like normal preferences, is to make it use as little resources as possible.
Why there isn’t any tag for it? Who knows.
Offline
Re: New Tag for resources URL
Gocom wrote:
It’s used when building URLs that point to the images (that’s it, nothing more or less, just alternative URL), and plugins can rely to it if the developer wants to do so (for example custom CDN integration).
Basically I do not understand how “images” is defined in this context. Anything named png|jpg|gif or is it actually more? Or – if one may dream? – is it even configurable?
Yoko for Textpattern – A free blog theme • Minimum 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
Re: New Tag for resources URL
maniqui wrote:
In my config.php file I’ve :
Then, I've a form
Do you really need to declare the variable twice, in the config.php and in a form? Is there maybe any code that would just work in config.php, as Gocom mentioned, to get processing to a minimum?
Yoko for Textpattern – A free blog theme • Minimum 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
Re: New Tag for resources URL
stephan wrote:
Basically I do not understand how “images” is defined in this context.
The constant ihu is used by core’s image tags, nothing more or less at the timebeing. In barebones (from cores perspective) it is just an URL, used to point the image tags to different domain/static subdomain/server.
Basically, image tags use ihu (http://static.domain.com) instead of hu (http://domain.com).
Do you really need to declare the variable twice, in the config.php and in a form? Is there maybe any code that would just work in config.php, as Gocom mentioned, to get processing to a minimum?
Julián’s example is returning the value from config. If you had a tag it would do same. The only extra step is that you need to first set the variable before you can use it. Of course you can from start use variable or use $variable
global ($variable['foo'] = 'bar'
).
Last edited by Gocom (2010-11-16 19:30:24)
Offline
Re: New Tag for resources URL
Gocom wrote:
The constant ihu is used by core’s image tags, nothing more or less at the timebeing.
So it only affects any txp:image(s) tags, right?
Do you really need to declare the variable twice, in the config.php and in a form? Is there maybe any code that would just work in config.php, as Gocom mentioned, to get processing to a minimum?
?
Sorry, I try to be more precise (thanks for bearing with me): I am aware that these are two different types of variables, one being a php variable, the other a txp var. Is there a chance to declare a variable just within config.php and be able to use it within a form without the need to declare and assign a value within a dedicated form?
Yoko for Textpattern – A free blog theme • Minimum 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
Re: New Tag for resources URL
stephan wrote:
So it only affects any txp:image(s) tags, right?
Yes. And such opens possibilities to plugin devs as the tag don’t hard link to the site’s location.
Is there a chance to declare a variable just within config.php and be able to use it within a form without the need to declare and assign a value within a dedicated form?
It doesn’t really matter where the variable is set, and it doesn’t need to be in dedicated form, nor the variable needs to be pulled from config. For example you could just set the variable in the page template to an URL you want use and forget the config.php altogether.
But yes, you can set the variable in the config.php too. You can set the variable ($variable
global) from PHP, like so:
$variable['foo'] = 'bar';
And then it can be returned it with:
<txp:variable name="foo" />
Last edited by Gocom (2010-11-16 19:45:23)
Offline
Pages: 1