Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Keep url segment consistent to render with alternative template?


Go to End


16 Posts   5586 Views

Avatar
martimiz

Forum Moderator, 1391 Posts

4 March 2011 at 10:02am

Hi Lisa,

Oops, overlooked it: of course calling just Link() from within Link() will not work. Called from within any other method in the Page controller, it should be $this->Link(). But if you want to override the Link() method itself, something like this should work:

function Link() {
   $originalLink = parent::Link();

   if (isset($this->urlParams['Action']) && $this->urlParams['Action'] == 'frame') {
      return $originalLink . 'frame';
   } else {
      return $originalLink;
   }
}

I'm not quite clear about the second part of your question. So maybe if the above works, you won't need that any more?

Also - but I'm not sure if this is what pointing at, $Top.Link will get you the Page_Controllers Link from within all kinds of nested control structures. So this, combined with the above????

Avatar
LisaB

Community Member, 28 Posts

10 March 2011 at 1:33am

Hi Martimiz, many thanks for your continued help! I feel really dumb, but I am using your code and can't quite get it to work still! Where I use $Link just in the main part of the templates it works fine, but I can't seem to get it to work inside the child control that I am using. I have my ArticleHolder page with the following:

<div id="Content" class="typography">		
   
   $Content
   <a href="$Link">$Link</a> <!--test to check Link() override function works outside control loop, which it does-->
  
   <ul id="NotesList">
   <% control Children %>
      <% if Photo %>
         <div class="thumbnail">
    	    <a href="$Link" title="Read more on &quot;{$Title}&quot;">$Photo.SetHeight(90)</a></div>
      <% end_if %>
      <li class="subject"><a href="$Link" title="Read more on &quot; $Title &quot;">$Title</a></li>
      <li class="noteText">$Content.FirstSentence... <br /><a href="$Link" title="Read more on &quot; $Title &quot;">Read more &gt;&gt;</a></li>
      <% if Children %>
         &nbsp;
      <% else %>
         <li class="noteDateContext">Contributed by $Author</li>
      <% end_if %>
   <% end_control %>
   </ul>

</div>

$Parent.Link and $Top.Link used within the control loop both give me the link to the ArticleHolder page, not the article itself, so $Link is what I want to use as it returns the right URL, then I just need to add frame to it if coming from a /frame page.

I am concerned that even if I get this to work for these children, it may not work throughout the site on all the different page types, and things like logging in won't keep the same frame template before and after login. I did it this way to try to avoid duplication of templates etc, but I wonder whether I should just make a whole new theme and keep it for the session or something like that.

Again, suggestions much appreciated!

Avatar
martimiz

Forum Moderator, 1391 Posts

10 March 2011 at 3:18am


Hi Lisa
OK - this time I sat down and did a real test. There are a lot of things that worked against you (us) in this setup:

1. the Link() method belongs to the Page class rather then the Page_Controller class, so no use overriding it in the controller.
2. when you <% control Children %>, what you get is a set of child page DataObjects, not Page_Controllers, so they do know about their Link() method but all functioncalls to their Page_Controller will fail.

There are probably lots of ways to do this, but this works for me. In you Page_Controller class:

public static $allowed_actions = array (
	'frame'
);

protected $urlExtension = '';

public function getURLExtension() {
	return $this->urlExtension;
}

function frame() {
	$this->urlExtension = 'frame/';
	return array();
}

And in your template

<% control Children %>
	...
	<a href="{$Link}{$Top.getURLExtension}" title="Read more on &quot; $Title &quot;">$Title</a>
	...
<% end_control %>

The only thing this does is when the frame() method is called, it sets the url extension from '' to 'frame/' and then renders the page normally. The bit $Top.getURLExtension will then get you the proper extension from the current Page_Controller itself.

Hope this will finally get you somewhere...

Avatar
LisaB

Community Member, 28 Posts

10 March 2011 at 5:08am

Hi Martimiz,

thanks so much for all your help and the time you've spent on this. Your advice has really improved my understanding and I am wading through the silverstripe book so am learning all the time! I haven't had a chance to try what you've suggested yet but I imagine it is exactly what I was looking to achieve. Only thing now is things like the log in button on the login form which I'm not sure if it will get the frame template before and after login - I will try and see.

In the mean time I have bodged it temporarily and used the frame theme and templates for the whole site, because getting it looking okay embedded in the other site is more important than the look of the main site. (It's a pain - the site I'm embedding it in can't be moved and its server doesn't meet SilverStripe requirements so I can't host it on there, but I need the silverstripe functionality!) I don't mind keeping the visual theme the same on the standalone and embedded sites, it's just that now the standalone site has no header, menu or footer because my template for embedding only uses the content area. When I saw your message I was trying to think of a way to test whether the site was being used standalone or in the other site's iframe, so that I could conditionally include or exclude those parts of the template. I will try your suggestion before opening a whole new can of worms trying to do it this new way though!

As you can tell I am a silverstripe noob and occasionally need to do stuff that I can't work out for myself, or at least that really holds me up time wise. No problem if not, but if I get stuck again I wonder if you would consider helping me out on a more formal (and paid!) basis? - maybe by phone or direct email or something?

Avatar
martimiz

Forum Moderator, 1391 Posts

15 March 2011 at 10:44pm

Hi Lisa,

I'm glad to have been at least of some help, and I hope you'll get this thing running :-) And sure, you can always pop me an email, but I would encourage you to keep posing questions on this forum, since the answers might help others as well :-)

Just curious though, since incorporating SilverStripe within a static site is such a hassle - and not very SEO as well... But you say the site can't be moved. Why would that be?

Avatar
LisaB

Community Member, 28 Posts

16 March 2011 at 12:16am

Thanks Martimiz,

I will definitely keep using the forums, it's just that I occasionally run into something that I need to get sorted against the clock and questions on the forum may not be answered for a while if at all. Plus there's the time difference between me in the UK and the SS guys in NZ and the added time it can take going back and forth via the forum which can introduce a lot of delay in answering a fairly simple question.

To answer your question, the site is provided for my company (small web retail outfit with a couple of shops) by a software company who provide an integrated ecommerce and point of sale system linked across the two shops and the website to manage the sales and stock. They host and manage the ecommerce website and related databases on their servers which don't meet all the silverstripe requirements (I'm working on this!). The back end of their website isn't a very capable cms and the SS ecommerce setup doesn't meet our retail needs, hence trying to combine the two in some way. For the time being I've created a standalone website using SS and am embedding the parts I want into the other site using frames, which is pretty much the worst possible solution! If I can get the hosts to upgrade their servers a little I will put an SS installation in a subdirectory of the other site. If not I will probably try to replicate the look and feel of the other site completely in SS and point a subdomain to it but I don't have time to do that just at the moment. Having said that if I had set out to do that first off I would probably have had it done by now, although in fairness the requirements have crept a little in that time! Anyway, a bit rambling but you get the gist - any cunning solutions/suggestions most welcome!

Avatar
martimiz

Forum Moderator, 1391 Posts

16 March 2011 at 1:22am

>> any cunning solutions/suggestions most welcome!

For the time being I can only wish you strength and endurance :-)

Avatar
LisaB

Community Member, 28 Posts

16 March 2011 at 2:22am

Thanks :-) - kind of glad I hadn't missed a "duh, you just need to do this" type solution! We'll get there I'm sure, by hook or by crook!

Go to Top