Forum for discussing general topics related to Couch.
31 posts Page 1 of 4
Hey KK - sorry for the direct approach here but I suspect there is a 'yes' or 'no' answer here...

Firstly, I apolgise for been annoying in the sense that I'm trying to do things here beyond the first scope of the great CMS, yet I suspect what I am trying to do might be possible, and while it may not appeal to everyone, it's possible and may demonstrate the flexibility of this CMS.

Ok, so I've adopted the notion to move my "snippets" into a folder in my root - its just makes more sense for someone supporting possible multiple sites in couch to be able to ignore the least ammount of possible overwrites as possible - I like snippets or "embeds" as I prefer them, in my root, thats just me and the way I've been for 4-5 years now.

OK - so, I've now got a file structure like this:

ROOT
- basic template.php
- basic template.php
- basic template.php

EMBEDS
standard_includeslikeheadersanfooters.inc
standard_includeslikeheadersanfooters.inc
list_view_of_news_type_stuff.tpl
list_view_of_news_type_stuff.tpl
list_view_of_news_type_stuff.tpl
etc

EMBEDS > JQM
my_jqjery_mobile_site_version_header.inc
my_jqjery_mobile_site_version_footer.inc

*Those JQM's sit in my embeds folder and the couch require looks like (and works as)
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>


MOBILE*
- News.php
- etc


Now the problem is that any
Code: Select all
<cms:show k_page_link />
will always reference the root of the site - is there anyway to prefix it so it can take "folder_root" or any method that allows me to separate the link structure so I can control the template it links to - i.e.

Code: Select all
<cms:show k_page_link />


inside "mobile" will inherit the root folder?

I know I am probably asking a lot here beyond the intended scope - I'm just sandboxing a site where by we can seperate "desktop" from "catered mobile" and keep a clean file structure - and again, I know this is probably not the intended way but it It would be awesome to be able to utilise subfolder like this.
Hi Patrick,

Could you please give a couple of concrete examples as to how the links *should* look like in the two versions and how they look at the moment?
Thanks.
Thinking about it and looking at the cmd:dump - is it possible to have a "root" like:

Code: Select all
<cms:show k_page_link root_aware='1' />


or define something in the header / template declaration that poses root_aware="1"

so any sub folder templates inherit the correct URL structure from the sub folder templates.

Perhaps I'm just mad and giving you a headache, if so I apologise profusely.
Patrick,

One good thing about Couch is that the moment we hit its limitations, we can make it use raw PHP to deliver the functionality (if required we can even create a custom tag of our own).
So we are in no way limited by k_page_link if it does not serve your need (unique though it might be).

The point is, I haven't completely understood the exact scenario yet (sorry, but I do tend to need more information than others to understand things :) ).

If you could, as I asked in the previous post, give me a few *concrete* examples (of the names/physical locations of the templates/embeds involved, the URL they are accessed as and finally what the link generated looks/should_look like), I am sure we can devise a solution.

Thanks.
Hi KK - Sorry, I'm a bit impulsive (as you probably know by now) and for that I apologise. Sent you a PM that should make sense, I hope :S
Site structure - for others (to clarify this):

I have a standard site structure except I have moved / changed the config so my "snippets" are in the site root as "embeds".

http://mysite.com/news.php


Above is the standard site news section.

Now, below is a link to the jQuery Mobile "Experiment" which resides in a subfolder of the site root...

Structure is: http://mysite.com/mobile/news.php

I have the list function in place (basically a duplication of my "desktop site" in the root, however the link
Code: Select all
<cms:show k_page_link />
always reverts to the site root.

http://mysite.com/mobile/news.php

just like

http://mysite.com/news.php

The links from both always refer to
Code: Select all
http://mysite.com/news.php


Where as any
Code: Select all
<cms:show k_page_link />
inside the "mobile/" folder should (desired) link to "mobile/" i.e. the root folder (physical) of the link on the server.


I hope this makes sense, I don't know how well I explained it...sorry.
Thanks. I get it now.
So basically this is the scenario -

You have two versions of the same site - one 'normal' and another 'mobile'.
The way you have setup the templates is that you have two for each section.
So, taking the example of news section, you have 'news.php' and 'mobile/news.php'
Template 'news.php' serves to define the editable regions and also as the 'normal' view of the news section.
e.g. http://www.site.com/news.php - lists cloned pages of 'news.php'.
Template 'mobile/news.php', on the other hand, simply serves as the 'mobile' view of news section (i.e. does not define editable regions of its own. Uses the regions defined by 'news.php').
e.g. http://www.site.com/mobile/news.php - also lists cloned pages of 'news.php'.

Easy to see that the news items listed by 'mobile/news.php' will link back to 'news.php' as that is the template they really belong to (e.g. http://www.site.com/news.php?p=11 or http://www.site.com/mobile/some-news.html).

What you wish is that the pages being listed by 'mobile/news.php' should show their links as belonging to 'mobile/news.php' so that clicking on any page from the list leads back the visitor to the mobile version. Right?

While I have my reservations about using this approach for having a mobile version of the site, sticking to the problem that you have, I think one way of doing it could be this -

The existing code in 'mobile/news.php' should be something like this
Code: Select all
<cms:pages masterpage='news.php'>
     <a href="<cms:show k_page_link />"><cms:show k_page_title /></a><br />
</cms:pages>

Make the following modification to the snippet above
Code: Select all
<cms:set my_template_link=k_template_link />
<cms:pages masterpage='news.php'>
     <a href="<cms:show my_template_link />?pid=<cms:show k_page_id />"><cms:show k_page_title /></a><br />
</cms:pages>

As you can see, instead of using 'k_page_link', we are using the template's link (i.e. 'mobile/news.php') and appending to it the id of the page being listed as a querystring parameter. e.g. a link could look like http://www.site.com/mobile/news.php?pid=38

Clicking on any of the links would now lead back to the 'mobile/news.php'. We now check if the parameter named 'pid' is present in the querystring
Code: Select all
<cms:set my_page_id="<cms:gpc 'pid' method='get' />" />
<cms:php>
    global $CTX;
    $my_page_id = $CTX->get( 'my_page_id' );
    if( !KFuncs::is_natural($my_page_id) ){
        $CTX->set( 'my_page_id', '' );
    }
</cms:php>

The bit of PHP is just some sanity checking to prevent unwanted inputs.
Next, if the page's id is indeed present, we make the template show just that page (instead of the listing). In a way, we create a page-view.
Code: Select all
<cms:if my_page_id >
    <cms:pages masterpage='news.php' id=my_page_id >
         <a href="<cms:show my_template_link />?pid=<cms:show k_page_id />"><cms:show k_page_title /></a>
         <cms:show desc />
         .. all regions of the page available here ..
    </cms:pages>
</cms:if>

The complete code is as follows:
Code: Select all
<cms:set my_page_id="<cms:gpc 'pid' method='get' />" />
<cms:php>
    global $CTX;
    $my_page_id = $CTX->get( 'my_page_id' );
    if( !KFuncs::is_natural($my_page_id) ){
        $CTX->set( 'my_page_id', '' );
    }
</cms:php>

<cms:set my_template_link=k_template_link /> 
<cms:if my_page_id >
    <cms:pages masterpage='news.php' id=my_page_id >
         <a href="<cms:show my_template_link />?pid=<cms:show k_page_id />"><cms:show k_page_title /></a>
         <cms:show desc />
    </cms:pages>
<cms:else />
    <cms:pages masterpage='news.php'>
         <a href="<cms:show my_template_link />?pid=<cms:show k_page_id />"><cms:show k_page_title /></a><br />
    </cms:pages>
</cms:if>

Does this help? Please let me know. Thanks.
Hi KK,

Thank you very, very much for this solution / approach. I have it working now for a few of my clonables.

May I ask, what reservations do you have regarding this? I'm curious ;)
I've been toying a little further with this and I may sideline it - I think it will get too messy to get working Folders and Archives.

I have another possible and somewhat cleaner approach in mind but wanted to know if it's possible:

1. Basically, could I take a copy of the "desktop" (http://www.mydomain.com) site, put it in a folder called "mobile" (or sub domain for that matter).

2. Alter the config.php values to set the new base "K_SITE_URL" as http//:subdomain.mydomain.com and apply the same database vales as the desktop site.

3. Create my Mobile templates but they would not have any defined regions etc in them

Would those templates in step three be able to pull data from the single database using master page declaration to match the main site?
I think it will get too messy to get working Folders and Archives.

This was one of the reasons for my 'reservation' on your approach :)

Before we discuss further this issue, could you please let me know how exactly are you going to decide (detect) if a visitor should be shown the 'mobile' version instead of the normal one?
31 posts Page 1 of 4