Hello,
Is it possible to somehow use built in page controls in Content area?
I would like to use e.g. $Now.Year or $Title or $CurrentMember.FirstName inside the Content without having to make templates for this..
Thanks
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.
- Page 11(current)
- 2
- 3
- Next 10 entries
Do you mean inside of the $Content output itself?
yes..
how about...
put something like $MyContent instead of $Content in your Pages.ss
create a function like...
function MyContent() {
$vd = new ViewableData();
$t = SSViewer::fromString('<% control CurrentPage %>'.$this->Content.'<% end_control %>');
$ad = new ArrayData(array('CurrentPage' => $this));
return $vd->customise($ad)->renderWith($t);
}
...it's just a guess, p[robably overcomplicated, but I think it'll work
UserForms requires the $UserDefinedForm variable in the Content area of the form page, so that seems to be an example of it working somehow. If I were you, I'd start by looking under the hood of the UserForms module.
I'd disagree Ryan - I've looked at that before and it does a straight str_ireplace for the "$UserDefinedForm" with the userform - not very helpful to access the full power of the standard page controls for merging things like $Now
swaiba, can you help me understand your example a little better? I'd like to use this idea for something a little different. Let's say, for example, I have a sub template file already made to display what I want. which would make your example more like this:
function MyContent() {
$vd = new ViewableData();
$t = SSViewer::getTemplateFile('mysite/include/SubTemplate.ss');
$ad = new ArrayData(array('CurrentPage' => $this));
return $vd->customise($ad)->renderWith($t);
}
What would you put into the WYSIWYG to make it render this? "$MyContent"? Wouldnt that just display "$MyContent" with the rest of what is in your HTMLEditorField rather than call the function?
Thanks!
sure...
you see I think you could get away with...
the function would go in your Page_Controller...
function MyContent() {
$t = SSViewer::fromString($this->Content);
return $this->customise()->renderWith($t);
}
and the $MyContent would go into templates/Pages.ss replacing $Content - this mean where the template would get the "Content" and put it ont he page it calls the MyContent function and this in turn takes the "Content" and treats it as a template. because we are in "Page" context it should merge.
My previous example did a little more to create it's own merging/rendering process, wrap the "Content" in a control and then pass the page data in... I did this becasue it seemed wrong to render within itself...
function MyContent() {
$vd = new ViewableData();
$t = SSViewer::fromString('<% control CurrentPage %>'.$this->Content.'<% end_control %>');
$ad = new ArrayData(array('CurrentPage' => $this));
return $vd->customise($ad)->renderWith($t);
}
- Page 11(current)
- 2
- 3
- Next 10 entries