1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / adding content to the head section

adding content to the head section

8 posts, 0 answered
  1. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    30 Apr 2008
    Link to this post
    greetings again, I've stumbled on a new roadblock here and I'm wondering if someone can help me out. My master page has a content placeholder inside the <head>. normally this would allow me to add custom scripts, styles, meta, etc to only specific pages, which is great that's what I need.

    but I can't seem to figure out how to do this in sitefinity. my master page has the content placeholder in the head section, but I can't seem to find any place to add content to it, and I really need this feature. my page has a background banner which changes based on the page you're on, but it's part of the main structure of the site, so it's defined in the master page.

    so I need a way to override this in every page, can this be done?

    thanks
  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    01 May 2008
    Link to this post
    Hello SelArom,

    there are several ways to achieve this. First and the easiest is to create multiple themes for all the backgrounds you are using. Now, if you have too many background this may not be so easy and so simple.

    Second solution you have is to write some code in your masterpage. Namely, when generating a template from a MasterPage you will be offered to upload the code-behind file as well. So here you can dynamically attach CSS files based on the page name, url or anything of that matter.

    You could also replace the css-background with an image (if that's an option).

    I hope that one of these solutions will work for you. Let me know if you have any additional questions.

    Greetings,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    01 May 2008
    Link to this post
    thanks for your reply. I did end up using the code behind on the master page to change the required css, but while I am glad that this workaround is possible, it is a less than elegant solution. It really would be great to be able to override the head at the page level, so that instead of attaching full sheets at run time dynamically (adding overhead to the page load) i can just statically assign certain pages to be changed.

    this is also advantageous for certain pages such as those that need custom javascripts embedded but dont' need to be placed in every single page. can you save this as a feature request?

    thanks
  4. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    01 May 2008
    Link to this post
    Hello SelArom,

    I have attached a simple (and I mean, very simple) user control here that you can drop on a page and then when you edit it you can set the url of the css file that you want to insert in a head tag. You can go and extend this control by giving it a possibility to insert more than one css file, javascript... or anything that you may find useful.

    I just wanted to show you the idea behind this and I hope you'll be able to use it. The control itself has no markup so it won't be visible, and you can add that in design code it displays a message like "Utility control" or something like that so that the average users don't confuse it with something they don't need :)

    I hope you'll find it helpful.

    Sincerely yours,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    01 May 2008
    Link to this post
    thanks for your reply! I don't think the attachment was saved but that's okay because isn't this the functionality that's already available in the page properties? it allows me to attach stylesheets to individual pages, and this is indeed what I am doing as a workaround (and it does work too) until such time that head tags are editable at the page level.

    I really think this is a feature you should consider adding, because while I CAN add a stylesheet individually, this means I would have to make a new style sheet for every single page that needs a custom style! Let me give you an example of what I mean:

    let's say I have a table that has a css class .tablebox that defines its th and td elements to be text-aligned left. that way all my tables will have this style and my site will look consistent. In addition, I have other stylings to caption, background, etc so that it all looks pretty and consistent.

    then I stumble upon a need to keep ALL of the stylings EXCEPT that I want all of the th text to be centered. I could make a new class, duplicate ALL the other stylings, changing just the th so that the text is centered... OR I could make a new stylesheet overriding that one tag, then attaching it to the page (which is your suggestion and my current workaround)...

    OR I could just edit the pages head tag and say <style type="text/css"> th { text-align: center; } </style> and be done with it. I'm not sure exactly how your implementation works, but remember that master pages now do include a content placeholder element in the head, so I'm guessing it would be a straight shot to enable some kind of functionality using what's already there..

    of course I could be way off :)

    thanks for listening!
  6. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    02 May 2008
    Link to this post
    Hi SelArom,

    first of all I apologize for forgetting to attach the control. Happens to me sometimes :)

    This time I believe you should be able to download the HeadInsert.zip file which contains a simple user control. The implementation is based on the fact that head element has an attribute runat="server", which means you can access it without needing a content place holder. I dynamically create a HtmlGeneric control link, set it's attributes (which I get from the HeadInsert control's properties) and then add this control to the Controls collection of head control. If you are to make a designer for this control (see my post here on how to do that : http://blogs.sitefinity.com/Ivan/Post/08-04-23/how_to_create_a_control_designer_for_user_controls.aspx ) you can really make a powerful and flexibile Head section editor. But it's up to your requirements and the amount of time you have.

    I didn't really make the attached control very user friendly, but you'll see my idea.

    Let me know if you have any additional questions or need advice in any way.

    Regards,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    02 May 2008
    Link to this post
    thanks for following up. I am going to play with this but I belive it would be much more practical to implement this at the page level. You already have a section for title, keywords, description, why not an extra textbox for additional head content?

    I messed with it for a while to see if I could figure out a way to extend a page to include this information but I just couldn't figure it out. I see that the description and keywords are fields in the database, but I'm not sure how I can extend things to include a "head" field. I tried the working with meta fields on generic content but didn't find any way to link that to a page.

    it was fun getting deeper into the cms and I'd love to continue but am I trying to do something that is not possible with the architecture of sitefinity? in other words, is this something you guys have to do or is there some way for me to extend a page to include this information?

    I'd be happy to give it a shot if you can point me in the right direction :)

    thanks
  8. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    03 May 2008
    Link to this post
    Hi SelArom,

    we've got previously request of this kind (to add some features to the pages), but since it is one of the cornerstones of the CMS, you can see how it's not really something that we can just add and see how it goes. I've written your requests down and we'll discuss this, but I cannot promise anything in this area.

    We do not have any guidelines for extending pages in the way you'd like to do and for the moment being I am strongly suggesting you use the control approach.

    The conclusion... we will think about it and discuss it, but no promises at this point.

    Let me know if you need help with anything else. 

    Best wishes,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
8 posts, 0 answered