2

I have the following page:

<apex:page docType="html-5.0" standardController="Transaction__c"  extensions="OptionComparisonDownload"
       name="Option Comparison" readOnly="true" applyHtmlTag="false"
       showChat="false" showHeader="false" standardStylesheets="false" sidebar="false">
    <html>
        <head>
            <c:StyleLibrary includeBootstrap="false" includeJqueryUI="false" includeSalesforce="false" />
        </head>
        <body>
            <apex:form >
                <c:OptionComparison options="{!Options}" />
            </apex:form>
        </body>
    </html>
</apex:page>

For some reason, my styles and javascript in the StyleLibrary component are being moved to the top of the body even though I'm clearly placing them in the head. Why is Salesforce doing this? How can I work around it? My end goal is to turn this into a PDF with renderAs="PDF". When I switch it to PDF, it spews out my CSS because it's being included in the wrong place.

I could refactor things out into a static resource, but I have to include some things with the $Resource variable, and it's a lot easier for us to collaborate on a component than a static resource.

  • I have a applyHtmlTag="false" docType="html-5.0" page where the content does stay in the head section but that is not indirecting through a component. Perhaps what you are seeing is a "feature" of components and you will have to put the content inline. – Keith C Jul 20 '15 at 23:03
  • It is a 'feature'. Discovered it was being wrapped with a span, and that led me to my answer. – ricksmt Jul 21 '15 at 16:29
  • Never noticed the layout attribute - good to know. – Keith C Jul 21 '15 at 16:36
1

Add this attribute to the definition of your StyleLibrary component: layout='none'.

The apex:component has a layout attribute with three possible values: inline (wrap the component content with a span), block (wrap the component content with a div), and none (insert the component content as is; no wrapper). Use layout='none' in order to achieve the desired behavior; otherwise, Salesforce defaults this value to inline and will wrap the content with a span which is invalid in the head element.

| improve this answer | |

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.