Template inheritance - how to resolve duplicate usage

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












Some time ago my team and I decided to break out some often-used fields into components that can be inherited, a Heading field being one of them. We put the Heading field into it's own template and started using it as one of the base templates for other templates.



As we started using this component we discovered that when you have more than one component on the same page that uses it, the value of one of the Heading fields will be shared across all instances of that field on that page. My question is: Is there a way to make inherited fields unique to the parent item that uses it? Or are we just doing it wrong?










share|improve this question

























    up vote
    2
    down vote

    favorite












    Some time ago my team and I decided to break out some often-used fields into components that can be inherited, a Heading field being one of them. We put the Heading field into it's own template and started using it as one of the base templates for other templates.



    As we started using this component we discovered that when you have more than one component on the same page that uses it, the value of one of the Heading fields will be shared across all instances of that field on that page. My question is: Is there a way to make inherited fields unique to the parent item that uses it? Or are we just doing it wrong?










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Some time ago my team and I decided to break out some often-used fields into components that can be inherited, a Heading field being one of them. We put the Heading field into it's own template and started using it as one of the base templates for other templates.



      As we started using this component we discovered that when you have more than one component on the same page that uses it, the value of one of the Heading fields will be shared across all instances of that field on that page. My question is: Is there a way to make inherited fields unique to the parent item that uses it? Or are we just doing it wrong?










      share|improve this question













      Some time ago my team and I decided to break out some often-used fields into components that can be inherited, a Heading field being one of them. We put the Heading field into it's own template and started using it as one of the base templates for other templates.



      As we started using this component we discovered that when you have more than one component on the same page that uses it, the value of one of the Heading fields will be shared across all instances of that field on that page. My question is: Is there a way to make inherited fields unique to the parent item that uses it? Or are we just doing it wrong?







      templates






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 5 hours ago









      Necromancer

      335




      335




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote













          A solid option is to build components that have a data source item rather than relying purely on fields defined on the page.




          Here's a scenario to help explain what I mean:



          Let's say you need to render a hero on the page, along with a few promotional items. I would imagine that the hero image is defined on the page, since many of those page types could use a hero. We add a Page Content component to render Content text and the Hero image.



          enter image description here



          I could add more fields to the page template, but why not have the component reference a data source designed specifically for what's need? So after some more development, improved styles... you add new components with data sources. We add two Promo components configured with local or global data sources.



          enter image description here



          Note: This was demoed with SXA. I encourage you to give that product a spin to see just how simple this can be.






          share|improve this answer



























            up vote
            0
            down vote













            As Michael mentions, you are doing it wrong. You have a page item that has fields on it, and then building components that pull fields from the current context item. As Michael noted, you should always build components that are reusable with a data source (with fields) that are contained within another item. That way if you want to add 50 headline components to a page, you don't run into a scenario where you can't because you need to add another headline to your page template.



            Having said all that, there is a way you can get around that. It's bad practice, and I highly recommend that you do not follow this. You could create on your headline component a rendering parameter. This rendering parameter would include the name of the field to pull from. Example, if you had on your context item 5 headline fields, such as (headline 1, headline 2, etc), you could specify in the rendering parameters that this component will pull in the value headline 1. Then on the second headline component on that same page, you could set the rendering parameters to pull from headline 2. This would also allow you to get around the issue of building 5 headline components for a page.



            But like I said, this is a bad practice.






            share|improve this answer




















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "664"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f13901%2ftemplate-inheritance-how-to-resolve-duplicate-usage%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote













              A solid option is to build components that have a data source item rather than relying purely on fields defined on the page.




              Here's a scenario to help explain what I mean:



              Let's say you need to render a hero on the page, along with a few promotional items. I would imagine that the hero image is defined on the page, since many of those page types could use a hero. We add a Page Content component to render Content text and the Hero image.



              enter image description here



              I could add more fields to the page template, but why not have the component reference a data source designed specifically for what's need? So after some more development, improved styles... you add new components with data sources. We add two Promo components configured with local or global data sources.



              enter image description here



              Note: This was demoed with SXA. I encourage you to give that product a spin to see just how simple this can be.






              share|improve this answer
























                up vote
                3
                down vote













                A solid option is to build components that have a data source item rather than relying purely on fields defined on the page.




                Here's a scenario to help explain what I mean:



                Let's say you need to render a hero on the page, along with a few promotional items. I would imagine that the hero image is defined on the page, since many of those page types could use a hero. We add a Page Content component to render Content text and the Hero image.



                enter image description here



                I could add more fields to the page template, but why not have the component reference a data source designed specifically for what's need? So after some more development, improved styles... you add new components with data sources. We add two Promo components configured with local or global data sources.



                enter image description here



                Note: This was demoed with SXA. I encourage you to give that product a spin to see just how simple this can be.






                share|improve this answer






















                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  A solid option is to build components that have a data source item rather than relying purely on fields defined on the page.




                  Here's a scenario to help explain what I mean:



                  Let's say you need to render a hero on the page, along with a few promotional items. I would imagine that the hero image is defined on the page, since many of those page types could use a hero. We add a Page Content component to render Content text and the Hero image.



                  enter image description here



                  I could add more fields to the page template, but why not have the component reference a data source designed specifically for what's need? So after some more development, improved styles... you add new components with data sources. We add two Promo components configured with local or global data sources.



                  enter image description here



                  Note: This was demoed with SXA. I encourage you to give that product a spin to see just how simple this can be.






                  share|improve this answer












                  A solid option is to build components that have a data source item rather than relying purely on fields defined on the page.




                  Here's a scenario to help explain what I mean:



                  Let's say you need to render a hero on the page, along with a few promotional items. I would imagine that the hero image is defined on the page, since many of those page types could use a hero. We add a Page Content component to render Content text and the Hero image.



                  enter image description here



                  I could add more fields to the page template, but why not have the component reference a data source designed specifically for what's need? So after some more development, improved styles... you add new components with data sources. We add two Promo components configured with local or global data sources.



                  enter image description here



                  Note: This was demoed with SXA. I encourage you to give that product a spin to see just how simple this can be.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 5 hours ago









                  Michael West

                  7,27721245




                  7,27721245




















                      up vote
                      0
                      down vote













                      As Michael mentions, you are doing it wrong. You have a page item that has fields on it, and then building components that pull fields from the current context item. As Michael noted, you should always build components that are reusable with a data source (with fields) that are contained within another item. That way if you want to add 50 headline components to a page, you don't run into a scenario where you can't because you need to add another headline to your page template.



                      Having said all that, there is a way you can get around that. It's bad practice, and I highly recommend that you do not follow this. You could create on your headline component a rendering parameter. This rendering parameter would include the name of the field to pull from. Example, if you had on your context item 5 headline fields, such as (headline 1, headline 2, etc), you could specify in the rendering parameters that this component will pull in the value headline 1. Then on the second headline component on that same page, you could set the rendering parameters to pull from headline 2. This would also allow you to get around the issue of building 5 headline components for a page.



                      But like I said, this is a bad practice.






                      share|improve this answer
























                        up vote
                        0
                        down vote













                        As Michael mentions, you are doing it wrong. You have a page item that has fields on it, and then building components that pull fields from the current context item. As Michael noted, you should always build components that are reusable with a data source (with fields) that are contained within another item. That way if you want to add 50 headline components to a page, you don't run into a scenario where you can't because you need to add another headline to your page template.



                        Having said all that, there is a way you can get around that. It's bad practice, and I highly recommend that you do not follow this. You could create on your headline component a rendering parameter. This rendering parameter would include the name of the field to pull from. Example, if you had on your context item 5 headline fields, such as (headline 1, headline 2, etc), you could specify in the rendering parameters that this component will pull in the value headline 1. Then on the second headline component on that same page, you could set the rendering parameters to pull from headline 2. This would also allow you to get around the issue of building 5 headline components for a page.



                        But like I said, this is a bad practice.






                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          As Michael mentions, you are doing it wrong. You have a page item that has fields on it, and then building components that pull fields from the current context item. As Michael noted, you should always build components that are reusable with a data source (with fields) that are contained within another item. That way if you want to add 50 headline components to a page, you don't run into a scenario where you can't because you need to add another headline to your page template.



                          Having said all that, there is a way you can get around that. It's bad practice, and I highly recommend that you do not follow this. You could create on your headline component a rendering parameter. This rendering parameter would include the name of the field to pull from. Example, if you had on your context item 5 headline fields, such as (headline 1, headline 2, etc), you could specify in the rendering parameters that this component will pull in the value headline 1. Then on the second headline component on that same page, you could set the rendering parameters to pull from headline 2. This would also allow you to get around the issue of building 5 headline components for a page.



                          But like I said, this is a bad practice.






                          share|improve this answer












                          As Michael mentions, you are doing it wrong. You have a page item that has fields on it, and then building components that pull fields from the current context item. As Michael noted, you should always build components that are reusable with a data source (with fields) that are contained within another item. That way if you want to add 50 headline components to a page, you don't run into a scenario where you can't because you need to add another headline to your page template.



                          Having said all that, there is a way you can get around that. It's bad practice, and I highly recommend that you do not follow this. You could create on your headline component a rendering parameter. This rendering parameter would include the name of the field to pull from. Example, if you had on your context item 5 headline fields, such as (headline 1, headline 2, etc), you could specify in the rendering parameters that this component will pull in the value headline 1. Then on the second headline component on that same page, you could set the rendering parameters to pull from headline 2. This would also allow you to get around the issue of building 5 headline components for a page.



                          But like I said, this is a bad practice.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 24 mins ago









                          Dylan Young

                          2,6941836




                          2,6941836



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f13901%2ftemplate-inheritance-how-to-resolve-duplicate-usage%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              Installing NextGIS Connect into QGIS 3?

                              One-line joke