# Url parameters

**URL:** <https://www.ruby-forum.com/t/url-parameters/104067>\
**Category:** Radiant CMS\
**Created:** [May 13, 2007, 11:29pm UTC](https://www.ruby-forum.com/t/url-parameters/104067 "2007-05-13T23:29:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francesco\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c2a13f/32.png) [@Francesco\_L](https://www.ruby-forum.com/u/Francesco_L)\
**Post date:** [May 13, 2007, 11:29pm UTC](https://www.ruby-forum.com/t/url-parameters/104067/1 "2007-05-13T23:29:32Z")

</div>

s it possible to capture query parameters and use them inside tags?  
For example if I have a URL like this  
[http://www.mysite.com/books?lang=it](http://www.mysite.com/books?lang=it) can I caputre the lang parameter and  
pass it to some tags?  
Having a page made with to parts “it” and “eng” I could decide wiche  
part show in a way like this:  
\<r:content part=“LANG” /\> where lang is the url parameter captured.  
But this could be useful in many other situations I think.  
Thanks to everybody  
Francesco L.

---

<div class="post-metadata">

**Author:** ![Francesco\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c2a13f/32.png) [@Francesco\_L](https://www.ruby-forum.com/u/Francesco_L)\
**Post date:** [May 13, 2007, 11:37pm UTC](https://www.ruby-forum.com/t/url-parameters/104067/2 "2007-05-13T23:37:32Z")

</div>

Francesco,

Yes, if the page is uncached. Another option would be to use the  
language\_redirect idea where you have multiple sub-sites for each  
language, but I know that’s not ideal in terms of reuse. Anyway,  
inside a tag definition, you should have access to the request and  
response variables. There are discussions about this previously on  
the mailing list, just do a search at  
[http://radiantcms.org/mailing-list](http://radiantcms.org/mailing-list)

Sean

---

<div class="post-metadata">

**Author:** ![Francesco\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c2a13f/32.png) [@Francesco\_L](https://www.ruby-forum.com/u/Francesco_L)\
**Post date:** [May 14, 2007, 3:21am UTC](https://www.ruby-forum.com/t/url-parameters/104067/3 "2007-05-14T03:21:50Z")

</div>

> Francesco L.  
> If you’re willing to get down and dirty and write and extension, I’ve  
> had some thoughts on how to implement a better langauge  
> extension - the different trees provided by the language redirection  
> extension don’t strike me as particularily friendly to keep up  
> to date, and your suggestion is pretty close to what I’ve got in my  
> head.

Basically, there would be a parent ‘language selector’ page, all  
children below that point can have differently languaged parts.

When the parent page’s find\_by\_url method is called, it sets  
LanguagePage.language = ‘en’ (not 100% sure on the best mechanism, but  
that’ll do off the top of my head)

When children are asked for a page part, say ‘body’, they would first  
look for ‘body\_en’ and only revert to ‘body’ if that does not  
exist.

So you’d have a single tree of pages, but they would be served through  
different urls:

/en/books  
/de/books  
/fr/books

I’ve got no real use for international stuff in the forseeable future as  
I run a local site for local people, so I don’t think I can  
be bothered actually writing the code to do this, but I’ve got it all  
pretty much in my head if anybody wants some further detail to  
pursue it themselves or some monetary motivation for me to write it.

Dan.

---

<div class="post-metadata">

**Author:** ![Francesco\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c2a13f/32.png) [@Francesco\_L](https://www.ruby-forum.com/u/Francesco_L)\
**Post date:** [May 15, 2007, 1:47pm UTC](https://www.ruby-forum.com/t/url-parameters/104067/4 "2007-05-15T13:47:45Z")

</div>

> When children are asked for a page part, say ‘body’, they would first look for ‘body\_en’ and only revert to ‘body’ if that does not  
> exist.
> 
> So you’d have a single tree of pages, but they would be served through different urls:
> 
> /en/books  
> /de/books  
> /fr/books

I think its a interesting point of view. So all your pages have parts  
for all the languages that your site supports.

In the request you can get the browser default language, dont you? So  
the default language of the site will be the browser’s default. After  
the page is loaded, the user can select an specific language in the  
litle flags :).

Probably I will need something like this in a close future. It’s ok to  
implement this as an extension??

Thanks,  
Sylvestre  
Mergulhão

---

<div class="post-metadata">

**Author:** ![Francesco\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/c2a13f/32.png) [@Francesco\_L](https://www.ruby-forum.com/u/Francesco_L)\
**Post date:** [May 15, 2007, 10:43am UTC](https://www.ruby-forum.com/t/url-parameters/104067/5 "2007-05-15T10:43:31Z")

</div>

Thanks for the answers.  
The possibility of capturing query parameters is not limited to  
addressing different part of pages, but it could be useful in many ways,  
I hope this possibility will be included in standard radiant  
distribution.  
In this case I used it to include static html pages into radiant  
generated pages.  
I have a customer that decided one of his emplyee MUST do some pages  
using an editor like nvu. (Learning to use radiant cms is too difficult  
for her)  
But the rest of the site is generated from radiant, menu and pages etc.  
For the moment the tag is customised to my needs, but I think it could  
be easily modified to any needs.  
First of all I modified the site\_controller.rb according to this post  
[http://lists.radiantcms.org/pipermail/radiant/2007-February/003480.html](http://lists.radiantcms.org/pipermail/radiant/2007-February/003480.html)

Then I created a custom tag

…  
require ‘net/http’  
require ‘uri’

tag ‘inner\_site’ do |tag|

# site is the url of the site I want to include risposta is the html

page I will get back

```
site = tag.attr['site']
risposta=""

```

# this is the radiant pag with “inner\_site” tag for example

[http://www.mysite.org/including](http://www.mysite.org/including)

# the page “including” shoud be simply \<r:inner\_site

site=“[http://radiantcms.org](http://radiantcms.org)” /\>

```
server=request.env['PATH_INFO']

```

# this caputures the query string parameter (it should be made better

capturing all parameters in a hash with name and value, bu for the  
moment it woks) The var @pagina contains the stati html page I want to  
include. i.e /html/iniziative.html

```
tag.globals.page.request.params.each do | param |
  @pagina = param[1].to_s.dup
end
if site
  url = URI.parse(site)
  res = Net::HTTP.start(url.host, url.port) {|http|
    @pagina ? http.get(@pagina) : http.get("/html/iniziative.html")
  }

```

# here I replace every internal link with a link to the radiant page

adding in the url the query string for the new page  
#external links (those starting with http://) are leaved unchanged

# this part need a lot of work to be useful in every situation (pages

made with mac osx have different new line charachter, there should be a  
better way to control if the link is internal or external) but form my  
needs work enought.

# images and css paths are unchanged, so you will not see images and css

formatting  
res.body.each\_line {|line|  
risposta+= line=~/http/ ? line :  
line.gsub(/href=“(.\*)”/,“href="#{server}?pag=”+‘\1"’)  
}  
end  
risposta  
end

now you can use this form to include radiant site in your page  
[http://www.mysite.org/including?pag=/index](http://www.mysite.org/including?pag=/index)

–  
Francesco L.  
Ymir s.r.l.  
Viale Verona 190/11  
38100 Trento
