3217 Posts in 853 Topics by 812 members
| Go to End | Next > | |
| Author | Topic: | 3958 Views |
-
access controller functions inside <% control AllChildren %>

25 March 2010 at 3:19am
hello all,
In the template I´m iterating a group of subpages of a page using <% control AllChildren %>...
Inside the control tag I can access properties of the pages, which are of a certain page-type. For example:
<% control AllChildren %>
$prop1
$prop2
<% end_control %>no problem so far...
so because I can access these properties I think silverstripe is aware of the PageType.
But somehow I can´t access functions of the Controller which are defined in the Controller Class of the PageType.<% control AllChildren %>
$prop1
$prop2
$controllerFunctionReturnValue
<% end_control %>Is this not possible?
many thanx in advance,
florian -
Re: access controller functions inside <% control AllChildren %>

25 March 2010 at 6:51am
What does your method return?
-
Re: access controller functions inside <% control AllChildren %>

25 March 2010 at 10:04pm
hi baba-papa!
at the moment the function simply returns a string.
I just want to check first if it works...florian
-
Re: access controller functions inside <% control AllChildren %>

31 March 2010 at 2:40am
Hi!
I have exactly the same Problem. I am setting up a page made out of blocks in different languages.
<% control AllChildren %>
$Title<br />
$BlockContent<% control AllChildren %>
$Title<br />
$BlockContent
<% end_control %><% end_control %>
Title is being displayed, but the method BlockContent which returns a string is not?
-
Re: access controller functions inside <% control AllChildren %>

31 March 2010 at 7:52am
and another example which is not working:
<% if Children %>
<ul class="jobcategories">
<% control Children %>
<li class="jobcategory">
<h3><a href="$Link">$Title ($ActiveJobs.Count) $Hond</a></h3>
<p class="description">$Content</p>
</li>
<% end_control %>
</ul>
<% end_if %>$Hond is a method in the Controller which does not get called, what am i doing wrong?
-
Re: access controller functions inside <% control AllChildren %>

31 March 2010 at 8:20am
@spierala
I figured this our through irc,
You cant use the method from the template file from the Controller, you need to put it in the Class
because the control loop loops through the Model not the Controller..does this work for you?
-
Re: access controller functions inside <% control AllChildren %>

3 April 2010 at 5:17am
So, if we can't access the controller methods from within another template (or an include in my case), is there some way to create a method inside the model that can access the controller?
In my case, I'm trying to include a condensed version of a contact form in a sidebar, and rather than duplicate the form fields manually (which I wouldn't be able to do anyway due to the key generated on forms to prevent spam), I'm wanting to loop through the ContactForm method inside the ContactPage controller and output the information that way. However, since I can't directly access the method that returns the fields, is there another way?
Or, is there another way of accomplishing this task that I'm not aware of?
Here's a quick summary of what my code looks like (the page 'contact' is of the ContactPage type, which contains the method for the form fields):
<% control Page(contact) %>
<% control ContactForm %>
<form $FormAttributes>
...
</form>
<% end_control %>
<% end_control %>Unfortunately, my code inside '<% control ContactForm %>' never gets executed as that method is defined in the controller, not the model.
-
Re: access controller functions inside <% control AllChildren %>

7 April 2010 at 4:55pm
BradPlunkett - I think you'll run into trouble mixing controls / forms. Perhaps just put the ContactForm logic in your Page_Controller which can then be called on any pagetype just by going $ContactForm, rather than controlling over a specific page.
| 3958 Views | ||
| Go to Top | Next > |





