3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1709 Views |
-
Using Variable in < % control Page() %> ??

17 December 2008 at 2:32am
hey Guys,
i want to create a new pagetype, that loads just the $Content of another page.
so, the new pagetype has a new text DB field "showContent"<?php
class CreatePopup extends SiteTree {
static $db = array(
'showContent' => 'Text'
);
static $has_one = array(
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('showContent'), 'Content');
return $fields;
}
}class CreatePopup_Controller extends ContentController {
function init() {
parent::init();
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}
}
?>in my "CreatePopup.ss" File i can write
Hello i am loading Content from http://www.yoursite.com/$showContent/
Then there is no error and the Content of "$showContent" is shown.
But now, i want to use this code..<% control Page($showContent/) %>$Content<% end_control %>
So this PageType shoud show just the $Content of another Page. ("$showContent" contains the URLSegment of the page what should be loaded). But when i use this Variable in Control Page, i get this ERROR:
Parse error: syntax error, unexpected '}' in /tmp/silverstripe-cache-srv-www-vhosts-domain.com-httpdocs/.cache.srv.www.vhosts.domain.com.httpdocs.themes.domain.templates.CreatePopup.ss on line 53
Can someone Help me?
p.s.:
i tried to write a function in CreatePopup.php, but i'm not going on with it.. just many errors..function showControlContent($showContent) {
$existingCont = DataObject::get_one("SiteTree", "URLSegment = '$showContent'");
if($existingCont) {
$makeControlPageContent = "<% control Page(".$showContent.") %>$Title<% end_control %>";
return $makeControlPageContent;
}
} -
Re: Using Variable in < % control Page() %> ??

17 December 2008 at 2:58am Last edited: 17 December 2008 4:28am
hey boys ;)
I just put the "CreatePopup" pagetyp as childs of the pages..
so the "CreatePopup" pagetypes just make$Parent.Content
so i dont need variable, dont need extra DB field and its better sortet i think.. (that content what should be shown is popup must have an popupchild ;) )
P.S.: why is it good, that Variables dont work in <% control Page(..) %> (or code segments like this).. they did not work just even with " /$variable " or " /$variable "..
want to clear this fact to understand it!
-
Re: Using Variable in < % control Page() %> ??

17 December 2008 at 7:14am
You've found one of the limits of the template engine. It passes everything inside the parenthesises as a string to the method.
A better way of doing what you were doing would be to use a has_one to SiteTree, something like:
<?php
class CreatePopup extends SiteTree {
static $db = array(
);
static $has_one = array(
'showContent'=>'SiteTree',
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TreeDropdownField('showContentID', 'showContent', 'SiteTree'), 'Content');
return $fields;
}
}class CreatePopup_Controller extends ContentController {
function init() {
parent::init();Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}
}
?>Then in your template you can use
Hello i am loading Content from $showContent.AbsoluteLink
and, to get the content$showContent.Content
| 1709 Views | ||
|
Page:
1
|
Go to Top |
