Getting the top section nickname and other things

47 views
Skip to first unread message

tiofred

unread,
Apr 19, 2012, 4:53:08 PM4/19/12
to bed...@googlegroups.com
Ok, here I am, using sections and sub-sections, and sub-sub-sections to navigate in my site.
My publication has 5 top sections, and they all share the same layout, except for one div, changing color for each section.
I thought using the current section name in my layout to give the right css style to that div. But I don't know how to get the top section's nickname when I'm in a sub-sub-section. Any idea ?
Another thing :
in a view, matching a section of course, can I access to a content like :
<?php $section['doc-nickname']['url'] ?> or something close to that, instead of using <?php $section['childContents'][1]['url'] ?> which is not very informative about what is not really explicit about the content when you read the code ?
Thanks guys for the help, I've made a lot of progress so far.

Alberto Pagliarini

unread,
Apr 19, 2012, 6:07:56 PM4/19/12
to bed...@googlegroups.com
hi there,

2012/4/19 tiofred <frederi...@gmail.com>

Ok, here I am, using sections and sub-sections, and sub-sub-sections to navigate in my site.
My publication has 5 top sections, and they all share the same layout, except for one div, changing color for each section.
I thought using the current section name in my layout to give the right css style to that div. But I don't know how to get the top section's nickname when I'm in a sub-sub-section. Any idea ?

Well you can use the $section['pathSection'] array which contains the sections parents. It's build using sections id as array keys and ordered by depth: the first element will be the more distant ancient and the last element the parent. So the first item of pathSection array is your top section.

You may find useful also the BeFront::menu() method of BeFrontHelper that you find in bedita-app/views/helpers

 
Another thing :
in a view, matching a section of course, can I access to a content like :
<?php $section['doc-nickname']['url'] ?> or something close to that, instead of using <?php $section['childContents'][1]['url'] ?> which is not very informative about what is not really explicit about the content when you read the code ?

No, when you match a section you have a simple list of the contents inside it because the searched item is the section and in the more general contest you don't know what contents are in a section.
Instead when you match a content you will find it in $section['currentContent'] and $section['contentRequested'] will be set to true.

If you need something like you said you have to manipulate the $section array in PagesController. 
For example:

protected function beditaBeforeRender() {
if (!empty($this->viewVars['section'])) {
$this->viewVars['section']['childContents'] = Set::combine($this->viewVars['section']['childContents'], '{n}.nickname', '{n}');
}
}

should resolve your issue.
 
Thanks guys for the help, I've made a lot of progress so far.

You're welcome and I'm very pleased of your progress :)

tiofred

unread,
Apr 25, 2012, 9:26:37 AM4/25/12
to bed...@googlegroups.com
Le vendredi 20 avril 2012 00:07:56 UTC+2, bato a écrit :
> hi there,
>
>
> 2012/4/19 tiofred <span dir="ltr">&lt;<a href="mailto:frederi...@gmail.com" target="_blank">frederi...@gmail.com</a>&gt;</span>
> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> Ok, here I am, using sections and sub-sections, and sub-sub-sections to navigate in my site.
>
> My publication has 5 top sections, and they all share the same layout, except for one div, changing color for each section.
>
> I thought using the current section name in my layout to give the right css style to that div. But I don&#39;t know how to get the top section&#39;s nickname when I&#39;m in a sub-sub-section. Any idea ?
> </blockquote>
>
>
> </div>
> Well you can use the <font face="&#39;courier new&#39;, monospace">$section[&#39;pathSection&#39;]</font> array which contains the sections parents. It&#39;s build using sections id as array keys and ordered by depth: the first element will be the more distant ancient and the last element the parent. So <b>the first item of pathSection array is your top section</b>.</div>
>
>
> </div>
> You may find useful also the BeFront::menu() method of BeFrontHelper that you find in bedita-app/views/helpers</div>
>
> </div>
>  </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
>
> Another thing :
>
> in a view, matching a section of course, can I access to a content like :
>
> &lt;?php $section[&#39;doc-nickname&#39;][&#39;url&#39;<WBR>] ?&gt; or something close to that, instead of using &lt;?php $section[&#39;childContents&#39;][1][&#39;<WBR>url&#39;] ?&gt; which is not very informative about what is not really explicit about the content when you read the code ?
>
> </blockquote>
>
> </div>
> No, when you match a section you have a simple list of the contents inside it because the searched item is the section and in the more general contest you don&#39;t know what contents are in a section.</div>
>
> Instead when you match a content you will find it in <font face="&#39;courier new&#39;, monospace">$section[&#39;currentContent&#39;]</font> and <font face="&#39;courier new&#39;, monospace">$section[&#39;contentRequested&#39;]</font> will be set to true.</div>
>
>
> </div>
> If you need something like you said you have to manipulate the $section array in PagesController. 
> For example:</div>
>
> </div>
> <font face="&#39;courier new&#39;, monospace">protected function beditaBeforeRender() {</font></div>
> </div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
>
> <font face="&#39;courier new&#39;, monospace">if (!empty($this-&gt;viewVars[&#39;<WBR>section&#39;])) {</font></div></div></blockquote>
> <blockquote style="margin:0 0 0 40px;border:none;padding:0px"><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
> <font face="&#39;courier new&#39;, monospace">$this-&gt;viewVars[&#39;section&#39;][&#39;<WBR>childContents&#39;] = Set::combine($this-&gt;viewVars[&#39;<WBR>section&#39;][&#39;childContents&#39;], &#39;{n}.nickname&#39;, &#39;{n}&#39;);</font></div>
> </blockquote></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
>
> <font face="&#39;courier new&#39;, monospace">}</font></div></div></blockquote>
>
>
> <font face="&#39;courier new&#39;, monospace">}</font></div>
> <font face="&#39;courier new&#39;, monospace">
> </font></div>
> <font face="arial, helvetica, sans-serif">should resolve your issue.</font></div>
>
>  </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> Thanks guys for the help, I&#39;ve made a lot of progress so far.
> </blockquote>
>
> </div>
> You&#39;re welcome and I&#39;m very pleased of your progress :)</div></div>

Ok, I'm gonna try that then.
Here's the thing now :
I have a section, nicknamed home_page
I want to write an action where I analyze the content of the section, and pass just selected data to the view. How do I do that ?
And how do I pass a variable to the layout ? Like the top section nickname ?

Thanks and sorry if I repeat myself sometimes.

tiofred

unread,
Apr 25, 2012, 9:30:09 AM4/25/12
to bed...@googlegroups.com
I forgot :
when I have an action, the $section variable isn't anymore available from the layout.ctp. I don't get that.
Thanks

bato

unread,
Apr 26, 2012, 4:47:58 AM4/26/12
to bed...@googlegroups.com
Hi tiofred,

don't worry about your questions, we are here to clarify any doubt about BEdita :)


Il giorno mercoledì 25 aprile 2012 15:26:37 UTC+2, tiofred ha scritto:
 
I have a section, nicknamed home_page

I start with a suggestion:

if your home page is a section you don't need to write any line of code to load it. Put your section as first of your publication tree and it will be loaded automatically when the browser points to the root of your website. In fact the "homePage" reserved word is used and by default the first section of the publication loaded.
So, for example if your publication tree is something like

Publication
|
|--- home
|--- news
....

pointing the browser to http://www.example.com the section named "home" is loaded. If you invert the order and you put "news" as first children of Publication then you could see that automatically "news" is loaded as home page.

Then if you need some specific view for the home page you should create the /views/pages/home_page.ctp file and it will be used for you "home" section.

A reading of http://docs.bedita.com/frontends/frontend-application-flow-and-callback-methods will help you to understand better how the frontend flow works and how to take advantage of callbacks.

 
I want to write an action where I analyze the content of the section, and pass just selected data to the view. How do I do that ?

well if you have read the article I linked above you should have figured out that every time a section is loaded some callbacks can be triggered. You should use on of these. In particular if your section nickname is "my-nickname" you should use the callback fired before the render happens in order to have available the "section" array:

protected function my_sectionBeforeRender() {
// here you can handle the section array you find in $this->viewVars['section']. In view you refer to it with $section var 
}

 
And how do I pass a variable to the layout ? Like the top section nickname ?

in CakePHP mode $this->set("varName", ...);
 
bye
alberto

bato

unread,
Apr 26, 2012, 5:12:35 AM4/26/12
to bed...@googlegroups.com


Il giorno mercoledì 25 aprile 2012 15:30:09 UTC+2, tiofred ha scritto:
when I have an action, the $section variable isn't anymore available from the layout.ctp. I don't get that.
Thanks

Right, if you use a specific action of your controller it skips the default loading of section data, so $section var isn't avaiable in view.

Ex:

try to call

PagesController::customMethod() method without call FrontendController::section() method that takes care of loading section data

Stefano Rosanelli

unread,
Apr 26, 2012, 5:52:14 AM4/26/12
to bed...@googlegroups.com
On 04/26/2012 11:12 AM, bato wrote:
Il giorno mercoledì 25 aprile 2012 15:30:09 UTC+2, tiofred ha scritto:
when I have an action, the $section variable isn't anymore available from the layout.ctp. I don't get that.

Right, if you use a specific action of your controller it skips the default loading of section data, so $section var isn't avaiable in view.

In fact BEdita in this case (specific/user created controller method) can't know if you want some section related data at all in your view.

If you want to load a specific section for your view, you may simply call
$this->section("<section-nickname>")
in your custom controller method, this will load the usual $section array.

ciao
Stefano

tiofred

unread,
Apr 30, 2012, 10:10:53 AM4/30/12
to bed...@googlegroups.com
Le jeudi 26 avril 2012 11:52:14 UTC+2, Stefano Rosanelli a écrit :
> On 04/26/2012 11:12 AM, bato wrote:
> <blockquote type="cite">Il giorno mercoledì 25 aprile 2012 15:30:09 UTC+2,
> tiofred ha scritto:
> <blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">when I
> have an action, the $section variable isn&#39;t anymore available
> from the layout.ctp. I don&#39;t get that.
>
>
> </blockquote>
>
>
>
> </div>
>
> Right, if you use a specific action of your controller it
> skips the default loading of section data, so $section var isn&#39;t
> avaiable in view.</div>
> </blockquote>
>
>
> In fact BEdita in this case (specific/user created controller
> method) can&#39;t know if you want some section related data at all in
> your view.
>
>
>
> If you want to load a specific section for your view, you may simply
> call
>
> $this-&gt;section(&quot;&lt;section-<WBR>nickname&gt;&quot;)
>
> in your custom controller method, this will load the usual $section
> array.
>
>
>
> ciao
>
> Stefano
>
> </div>
From beditaBeforeFilter() method, I'm trying to send the top pathSection nickname to the layout, for every page of the site. But I can't find a way to get that data in this method. Please help ;-)
Thanks guys!

Alberto Pagliarini

unread,
Apr 30, 2012, 4:28:28 PM4/30/12
to bed...@googlegroups.com

You should use the callback beditaBeforeRender() instead of beditaBeforeFilter(). In fact before filter is called before of the action method so you haven't any section data there.

Frédéric Donnet

unread,
May 1, 2012, 10:11:25 PM5/1/12
to bed...@googlegroups.com
Thanks, it works now!

A trivial question :
in a section, I have a multimedia content (a pic). I have a view for this section.
How can I display the pic, say in a img tag. ?
Thanks!

2012/4/30 Alberto Pagliarini <bat...@gmail.com>

Dante

unread,
May 2, 2012, 1:46:29 AM5/2/12
to bed...@googlegroups.com
Hi,
  
there's a specific helper to embed media (audio,video,image) in your template views: BeEmbedMediaHelper.

A simple example:

<img src="{$beEmbedMedia->object($media, ['URLonly' => true, 'width' => 200, 'height' => 200])}" alt="{$media.title}" />

Another example (from bedita/examples/wp.example.com):

{assign_associative var="options" mode="fill" width=100 height=100 modeparam="000000" upscale=true}
{assign_associative var="htmlAttr" style="float: left; width: 100px; height: 100px; margin: 10px 20px 10px 0"}
<a rel="gallery" title="{$media.title}" href="{$beEmbedMedia->object($media, $options)}" {$beEmbedMedia->object($media, $options, $htmlAttr)}</a>

You can find more examples here: http://docs.bedita.com/frontends/embedding-media-object.
Ciao ;)
Dante

Alberto Pagliarini

unread,
May 2, 2012, 3:57:28 AM5/2/12
to bed...@googlegroups.com
A little clarification about embed media example by Dante

2012/5/2 Dante <didoj...@gmail.com>

A simple example:

<img src="{$beEmbedMedia->object($media, ['URLonly' => true, 'width' => 200, 'height' => 200])}" alt="{$media.title}" />

this example works only with BEdita 3.2 series that uses Smarty 3. In BEdita 3.1 you have to create the associative array used as second parameters before calling the beEmbedMedia method as shown in other examples. 
Otherwise if you use CakePHP view engine you should write something like

<img src="<?php echo $beEmbedMedia->object($media, array('URLonly' => true, 'width' => 200, 'height' => 200)); ?>" alt="<?php echo $media['title']" />

the same tag <img/> is created with

<?php echo $beEmbedMedia->object($media, array('width' => 200, 'height' => 200)); ?>

The $media variable is a BEdita multimedia object (in your original question is the image object inside the section) and you find it in $section['childContents'] or $section['currentContent']

Other times you could have an image related to another object (as document) and you will find the image in the "relations" array of that object through the "attach" relation, for example

$section['currentContent']['relations']['attach']

Pay attention that beEmbedMedia use crop as thumbnail default option. If you want a full image thumbnail you should add at params array "mode" => "fill" and set only width or height.

A question. Are you using BEdita 3.1?


ciao!

------ bato -------

Frédéric Donnet

unread,
May 2, 2012, 2:28:16 PM5/2/12
to bed...@googlegroups.com


2012/5/2 Alberto Pagliarini <bat...@gmail.com>
Hi. Thanks for the tips, it works fine.
Now I'm gonna make a helper because I have to display the 5 latest news with a thumbnail picture, and a shortened text, in a div. And link those to a parametered view, to display only the clicked one. Gonna be fun.
I'm using latest stable BEdita, 3.1.6
Ciao ;-)

Frédéric Donnet

unread,
May 3, 2012, 10:35:18 AM5/3/12
to bed...@googlegroups.com


2012/5/2 Frédéric Donnet <frederi...@gmail.com>


Okay, another question :
In my view home_page, matching the HomePage section, I need to also have access to content from the section nicknamed "news", where I store some news content.
How do I do that ? (whether it's in an action method, or in a view)
Thanks.

Alberto Pagliarini

unread,
May 3, 2012, 11:12:12 AM5/3/12
to bed...@googlegroups.com
If you need a specific view for the section nicknamed "news"  you can simply create file views/pages/news.ctp (or .tpl)

If you need to perform some operations in your controller on that section you can use the callback newsBeforeFilter() (here you haven't section data yet) and newsBeforeRender().


2012/5/3 Frédéric Donnet <frederi...@gmail.com>



--
------ bato -------

Frédéric Donnet

unread,
May 3, 2012, 11:15:18 AM5/3/12
to bed...@googlegroups.com
That's not what I meant sorry.
I'll rephrase it :
I'm in a section A, and I need to have also access to the content of section B, to display say the latest content of section B in the view of section A.
How can I have access to the content of section B in the action/view A ? What do I call to load that data ?
Thanks.

2012/5/3 Alberto Pagliarini <bat...@gmail.com>

Stefano Rosanelli

unread,
May 3, 2012, 11:20:44 AM5/3/12
to bed...@googlegroups.com
On 05/03/2012 04:35 PM, Fr�d�ric Donnet wrote:
> In my view home_page, matching the HomePage section, I need to also
> have access to content from the section nicknamed "news", where I
> store some news content.

if you have a section with nickname "home_page" you may define a method
in your controller like

public function home_pageBeforeRender() {
// this will load in $newsContent array objects contained in "news"
section
$this->set("newsContent", $this->loadSectionObjectsByNick("news"));
}


Reply all
Reply to author
Forward
0 new messages