Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » access widget in template outside of the sidebar

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 511 Views
  • Anatol
    Avatar
    126 Posts

    access widget in template outside of the sidebar Link to this post

    Hi,

    how could I access widgets in e.g. the <head> of a template file. I need to define some local CSS styles depending on the content of a widget, and the CSS should go into the head of the HTML.

    I tried something like this

    <style type="text/css">
       <% control SideBar %>
          <% control blogPosts %>
             .latest-blog-post-$ID {
                   /* CSS here */
             }
          <% end_control %>
       <% end_control %>
    </style>

    but it doesn't work. I would appreciate any ideas.

    Cheers!
    Anatol

  • Anatol
    Avatar
    126 Posts

    Re: access widget in template outside of the sidebar Link to this post

    Hm, why is the answer always obvious a minute after I posted here? Anyway, it might be helpful for others. This works:

    <style type="text/css">
          <% control SideBar %>
             <% control Widgets %>
                <% if class = LatestBlogPost %>
                   <% control blogPosts %>
                      .latest-blog-post-$ID {
                         /* CSS here */
                      }
                   <% end_control %>
                <% end_if %>
             <% end_control %>
          <% end_control %>
       </style>

    Maybe there's a shorter way with less nesting, but for now that's sufficient.

    511 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.