21294 Posts in 5734 Topics by 2602 members
General Questions
SilverStripe Forums » General Questions » How can I insert different "blocks" [snippets, shortcodes] in main-text
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1146 Views |
-
How can I insert different "blocks" [snippets, shortcodes] in main-text

4 March 2010 at 1:33am
Hi,
how can I insert any stored informations in the normal textarea e.g. I have a table with Staff-Members and I will display at the startpage
"
Bla bla bla...
the latest three Staff-Members are: Tom, Cherry, Donaldbla, bla bla...
"Shure, I shold make a class or function an then... how can I insert a placeholder in the normal text??
Thanks
helloworld -
Re: How can I insert different "blocks" [snippets, shortcodes] in main-text

4 March 2010 at 9:20am
Hi,
You can create a function like this:
function showLatestStaff($limit = 3){
$staff = DataObject::get('Staff','','Date DESC','',$limit);
if($staff) return $staff;
return null;
}this function will return the latest 3 staff.
now in your template<% control showLatestStaff %>
<p>$Name</p>
<!-- Other DataObject properties -->
<% end_control %>hope it helps
cheers -
Re: How can I insert different "blocks" [snippets, shortcodes] in main-text

4 March 2010 at 9:37am
how can I insert a placeholder in the normal text?
For 2.3 you can do something like http://doc.silverstripe.org/doku.php?id=recipes:customising-content-in-your-templates. In 2.4 I believe there is support for actual wordpress like short codes within the content field.
-
Re: How can I insert different "blocks" [snippets, shortcodes] in main-text

4 March 2010 at 10:04am Last edited: 4 March 2010 10:11am
Hi Willr,
"In 2.4 I believe there is support for actual wordpress like short codes within the content field..." - good news!!!
I think it´s not practicable to make a few tens templates for every variant.
What is the "keyword" for this feature?
Tanks helloworld
-
Re: How can I insert different "blocks" [snippets, shortcodes] in main-text

4 March 2010 at 10:17am
@Carlos
sure - I can define a special template, but in this time I write
"blablabla *showLatestStaff* blablabla..." and I will change to "*showLatestStaff* bub bal bub"...
with a "static" template I win no prizes...
helloworld
-
Re: How can I insert different "blocks" [snippets, shortcodes] in main-text

5 March 2010 at 8:25am Last edited: 5 March 2010 8:33am
@Willr
Good Morning!
I read the recipe http://doc.silverstripe.org/doku.php?id=recipes:customising-content-in-your-templates
thats the right way for this problem or with this adaption http://www.silverstripe.org/general-questions/show/255882?start=0#post255940
I think it is possible to make a generaly solution like
e.g. placeholder is <% my_placeholder %>
draft:
function Content() {
$pattern= '/^<%.?%>$/i';$match = search every match...
loop:
$func = $match;if(function_exists($func)) {
$new_Content .= str_replace($match, $func, $this->Content);
}end_loop
return $new_Content;
}
function my_placeholder() {
return 'foo';
}Edit:
this is a good solution if I have seven PP-Buttons... look at http://www.silverstripe.org/archive/show/202803?start=8#post213912
| 1146 Views | ||
|
Page:
1
|
Go to Top |


