Diem snippets syndication

Create a manageable menu

December 16, 2009 by Thibault D

In this snippet we will create a manageable menu.


Deprecated snippet
Diem now provides a much better way to create and manage menus without any technical knowledge. Learn more about the new menu widget.


The links must be manageable from the admin application.
They must be activable/deactivable, and sortable. They can be internal or external links.

schema.yml

Link:  
  actAs:              [ Timestampable, Sortable ]  
  columns:  
    name:             { type: string(255), notnull: true }  
    title:            { type: string(255), notnull: false }  
    url:              { type: string(255), notnull: true, extra: link }  
    is_active:        { type: boolean, notnull: true, default: true }  

modules.yml

Content:  

  Global:  

    link:  
      components:  
        list:  

Update the project

php symfony doctrine:generate-migrations-diff  

php symfony doctrine:migrate  

php symfony dm:setup  

In the Content menu of the admin upper toolbar, a links section is now available.

We can drag & drop a page from the PAGES left panel into the "url" form field.
This way, if the page url change later, the link will be automatically updated.

We can write full urls like http://symfony-project.org

We can also use the "Loremize" box to automate test data creation.

Create the front interface

Click the "Add" button on the lower tool bar, and drag & drop a Link/List widget on the page.
Then edit the template /apps/front/modules/link/templates/_list.php and replace "echo $link" with:

echo _link($link->url)->title($link->title)->text($link->name);

Now we have a menu widget as specified above.

Add a comment

Comments

    Fork Diem on GitHub