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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

How can I insert different "blocks" [snippets, shortcodes] in main-text


Reply


6 Posts   1418 Views

Avatar
helloworld

Community Member, 14 Posts

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, Donald

bla, bla bla...
"

Shure, I shold make a class or function an then... how can I insert a placeholder in the normal text??

Thanks
helloworld

Avatar
carlos

Community Member, 41 Posts

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

Avatar
Willr

Forum Moderator, 5513 Posts

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.

Avatar
helloworld

Community Member, 14 Posts

4 March 2010 at 10:04am

Edited: 04/03/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

Avatar
helloworld

Community Member, 14 Posts

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

Avatar
helloworld

Community Member, 14 Posts

5 March 2010 at 8:25am

Edited: 05/03/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