Forum for discussing general topics related to Couch.
4 posts Page 1 of 1
Quick question ... maybe I need coffee or it is getting late ...
I know how to display content on another page, all of it, or specific (based on name, etc).

How about specifying the other page name in the URL?

Say I have:

I want to make a new file, where I only display some stuff in JSON format, like:

can I make the new page take the URL and output the content from blog.php "page name", based on the url that was called?

Should I be using Routes for this, or there is an easier way?

<cms:pages masterpage='blog.php' page_name='URLPARAMS'></cms:pages> or something
There are certainly some ways to do this or that, but the use-case is not clear. I suggest to do it the easiest way possible: add a querystring.

Next, cms:gpc can 'sense' the presence of 'json' in URL and you can output some code and abort the rest of the code:
Code: Select all
<cms:if "<cms:gpc 'json' />">
   <cms:capture into='json_page' >

   ... code to show your json stuff

   <cms:abort msg=json_page />

Additionally, you could tamper with .htaccess (add a rewrite rule), so whenever anyone requests '' Apache redirects user to '' and keeps the URL in address bar as requested (with 'api').
Wouldn't it be a solution?
active topics, google
Free support is never free.. Donate!
I don't specifically need another URL, your example with "" is much simpler for me anyway. I just couln't imagine how to do it.

I didn't know about <cms:gpc, I think this is exacly what I need. I will just output JSON instead of the normal content.


Edit: It works great just with your example. This community is awesome :)
I am just glad it helped :)

For anyone stumbling across this thread and wondering about .htaccess rule, here is a sample:

Code: Select all
<IfModule mod_rewrite.c>
RewriteEngine On

#If your website is installed in a subfolder, change the line below to reflect the path to the subfolder.
#e.g. for make it RewriteBase /subdomain1/subdomain2
RewriteBase /

#CUSTOM REQUEST: projects/16948 OR projects/16948/ DESTINATION: projects-view.php?rid=16948
RewriteRule ^projects\/(\d+?)\/??$ projects-view.php?rid=$1 [L,QSA]


I had to use such technique to maintain backward compatibility with some older software that needed to access couch-powered website by urls in a special format. While routes would do it as well, rewrite rule is sooo much faster and easier to do.

In the above sample, user types in browser or maybe some software requests following link: http://site/projects/16948
In reality, request is being redirected invisibly for user to link http://site/projects-view.php?rid=16948.

Hope it helps further on. ;)
active topics, google
Free support is never free.. Donate!
4 posts Page 1 of 1

Who is online

In total there are 2 users online :: 1 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: Google [Bot] and 1 guest