2

I know you can use fields to define the content in a page, for instance,

<div id="titleField">        
   <!--MS:<PageFieldTextField:TextField runat="server" ControlMode="Display"         FieldName="6867b1e3-d270-43f0-872d-6672f7dadf91">--><!--ME:</PageFieldTextField:TextField>-->           

That's great but can I do that and extend it to CSS? For instance....... what if I have a field that I would like a user to fill out that will ultimately be a background for a div?

Is that possible? Something like...........

     <div id="someField" style="background: url(<!--MS:<PageFieldTextField:TextField runat="server" ControlMode="Display" FieldName="6867b1e3-d270-43f0-872d-6672f7dadf91">--><!--ME:</PageFieldTextField:TextField>-->);">Some content, etc, etc </div>

Obviously this isn't correct syntax. But what is? This would allow me to give users the ability to style certain pages, elements, etc, all being defined within the page layout.

That said, I know I could do this with javascript and jquery on the client-side (in fact I have done it) but it's nice to do as much as I can before I get to that point. It's also perhaps a little easier, down-the-road, to manage. Also, obviously I'm editing the HTML page layout and have no broken the connection with aspx page yet. Again, for future people editing, changing, etc, in a perfect world I'd like to keep the customization in the HTML page. Maybe it's not possible that way? Thanks for any help you can provide.

  • Unless I'm missing some syntax that would allow you to do what you want, I believe you'd have to create a delegate control yourself that outputs the div with a style tag. Which is more or less what those out of the box helper controls are doing. – Cameron Verhelst Feb 25 '14 at 14:07
  • I was hoping this wasn't the case but feared it might be. – CeeMoney Feb 25 '14 at 14:33
  • I feel that's generally every SP developer's first reaction on a client's request :D. – Cameron Verhelst Feb 25 '14 at 14:36
  • Agreed. It gets tiring too. OOTB is far too often a fairy tale. – CeeMoney Feb 25 '14 at 15:10
1

Here is one approach I would take just to keep things as they are:

If you want to remain true in using snippets as they are presented, simply load that value onto your custom .html page layout or .htm master template. Wrap it in a div element that has either a unique id or unique class name. Then from your custom java script file, modify the DOM based on the value that was loaded onto the page.

  • Ultimately that's what I did. I used snippets for 95% of everything and injected javascript where needed across the board. – CeeMoney Jul 12 '14 at 0:11
  • And that's not a bad thing because more users do have JavaScript enabled by default AND sharePoint is pushing JavaScript as a dependable coding practice. – klewis Jul 14 '14 at 11:26
0

I've done something similar to that, if I understand correctly what you're asking. In my case, I had a list for each site that allowed the user to select colors (really just a fancy choice column) & provide links to images within the site's "Media" library.

What I did to apply the choices was have a hidden DVWP on the page that applied the CSS using conditional statements. Within the CSS itself, I called the user-added field values like so:

<xsl:if test="@CustomBackground='Yes'">
   <style>
   .banner {background-url('{@BackgroundImage}');}
   </style>
</xsl:if>

I had to play around with it to get everything working just right, but hopefully that can get you started in the right direction.

In my specific case, we were only modifying the front page. Potentially, though, you could probably drop the DVWP on any page you wanted - including library views, etc.

  • I've actually done exactly what you suggested above as well, modifying a DVWP. I was hoping with 2013 and the ability to modify page layouts as we can now, it'd be easier. – CeeMoney Feb 25 '14 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.