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.

Widgets /

Discuss SilverStripe Widgets.

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

access widget in template outside of the sidebar


Reply


2 Posts   567 Views

Avatar
Anatol

126 Posts

9 February 2012 at 12:11pm

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

Avatar
Anatol

126 Posts

9 February 2012 at 12:21pm

Edited: 09/02/2012 12:23pm

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.