I'm building multiple components that have the same attributes and html wrappers and so I was curious about ways to reuse some markup rather than redefining it on every custom component in this series.

For example just as the Id and Render attributes are default for every component I would like to have some include that makes several other attributes created by default. I was considering apex:include but I don't believe I can include other components just other VF pages.

I know how to include a component within a component but this is more difficult because I need the attribute declaration to come from a different component like so:

Parent/Wrapper Component:

<apex:component controller="WrapperController" layout="none">

    <!-- Define DEFAULT Component Attributes -->
    <apex:attribute name="attr1" assignTo="{!a1}" description="" type="String" required="true"/>
    <apex:attribute name="attr2" assignTo="{!a2}" description="" type="String" required="true"/>
    <apex:attribute name="attr3" assignTo="{!a4}" description="" type="String" required="true"/>

    <!-- Define Component -->
    <apex:outputPanel styleClass="wrapper-container" layout="block">

        <apex:componentBody />



Child Component Series

<apex:component controller="ExtendsWrapperController">

    <apex:attribute name="custom1" assignTo="c1" description="" type="String" required="true"/>



So first off I need to know is this possible or am I wasting my time? And then if so how should I look about doing this?

References: apex:include vs. Visualforce component, when and why?

  • 1
    Do you want to be able to use sub components in the <apex:componentBody /> and have them access attributes defined on the parent/wrapper component? Mar 1, 2016 at 20:45
  • Yes, that was part of the original goal I suppose. I couldn't find a way to make this work so I moved on to a a different approach which I outline here: salesforce.stackexchange.com/questions/111963/… Mar 1, 2016 at 20:54
  • @DanielBallinger For the sake of the question though is that possible? And could you provide an answer to bring some closure to the question? Mar 31, 2016 at 22:47


You must log in to answer this question.

Browse other questions tagged .