Symfony fixed elements on the page












0















I have the following problem, I have a template layout.html.twig which is loaded everywhere, in it I have a menu with categories downloaded from the database, and now my question is how to make a list of categories from the database in each controller from the machine, instead of each time download a category repository and all categories from it. I have been working in Symfony for a long time, but I create the API without views, hence the problem. Generally, I would like that after loading layout.html.twig a list of categories has been downloaded without my intervention, bypassing the loading of this list in every action of the controller.



I have fixed elements on the site, such as: category menu downloaded from the database, on the main page I have popular articles that also have to be on every subpage, and it makes no sense to download everything in every controller every time.



Any ideas?










share|improve this question



























    0















    I have the following problem, I have a template layout.html.twig which is loaded everywhere, in it I have a menu with categories downloaded from the database, and now my question is how to make a list of categories from the database in each controller from the machine, instead of each time download a category repository and all categories from it. I have been working in Symfony for a long time, but I create the API without views, hence the problem. Generally, I would like that after loading layout.html.twig a list of categories has been downloaded without my intervention, bypassing the loading of this list in every action of the controller.



    I have fixed elements on the site, such as: category menu downloaded from the database, on the main page I have popular articles that also have to be on every subpage, and it makes no sense to download everything in every controller every time.



    Any ideas?










    share|improve this question

























      0












      0








      0








      I have the following problem, I have a template layout.html.twig which is loaded everywhere, in it I have a menu with categories downloaded from the database, and now my question is how to make a list of categories from the database in each controller from the machine, instead of each time download a category repository and all categories from it. I have been working in Symfony for a long time, but I create the API without views, hence the problem. Generally, I would like that after loading layout.html.twig a list of categories has been downloaded without my intervention, bypassing the loading of this list in every action of the controller.



      I have fixed elements on the site, such as: category menu downloaded from the database, on the main page I have popular articles that also have to be on every subpage, and it makes no sense to download everything in every controller every time.



      Any ideas?










      share|improve this question














      I have the following problem, I have a template layout.html.twig which is loaded everywhere, in it I have a menu with categories downloaded from the database, and now my question is how to make a list of categories from the database in each controller from the machine, instead of each time download a category repository and all categories from it. I have been working in Symfony for a long time, but I create the API without views, hence the problem. Generally, I would like that after loading layout.html.twig a list of categories has been downloaded without my intervention, bypassing the loading of this list in every action of the controller.



      I have fixed elements on the site, such as: category menu downloaded from the database, on the main page I have popular articles that also have to be on every subpage, and it makes no sense to download everything in every controller every time.



      Any ideas?







      symfony twig






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 13:49









      PawelCPawelC

      389




      389
























          1 Answer
          1






          active

          oldest

          votes


















          3














          I would create a menuFragment method in my DefaultController, and use a sub-request to render it.



          https://symfony.com/doc/current/templating/embedding_controllers.html



          Some people will tell you that sub requests slow down your code, but it is not significant if you don't go overboard with it. 1-3 subrequest won't be a problem at all.






          share|improve this answer
























          • Hello, to go further than this answer, for menus have you tried KnpMenuBundle : symfony.com/doc/current/bundles/KnpMenuBundle/index.html

            – S. Bureau
            Nov 13 '18 at 14:02











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282507%2fsymfony-fixed-elements-on-the-page%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          I would create a menuFragment method in my DefaultController, and use a sub-request to render it.



          https://symfony.com/doc/current/templating/embedding_controllers.html



          Some people will tell you that sub requests slow down your code, but it is not significant if you don't go overboard with it. 1-3 subrequest won't be a problem at all.






          share|improve this answer
























          • Hello, to go further than this answer, for menus have you tried KnpMenuBundle : symfony.com/doc/current/bundles/KnpMenuBundle/index.html

            – S. Bureau
            Nov 13 '18 at 14:02
















          3














          I would create a menuFragment method in my DefaultController, and use a sub-request to render it.



          https://symfony.com/doc/current/templating/embedding_controllers.html



          Some people will tell you that sub requests slow down your code, but it is not significant if you don't go overboard with it. 1-3 subrequest won't be a problem at all.






          share|improve this answer
























          • Hello, to go further than this answer, for menus have you tried KnpMenuBundle : symfony.com/doc/current/bundles/KnpMenuBundle/index.html

            – S. Bureau
            Nov 13 '18 at 14:02














          3












          3








          3







          I would create a menuFragment method in my DefaultController, and use a sub-request to render it.



          https://symfony.com/doc/current/templating/embedding_controllers.html



          Some people will tell you that sub requests slow down your code, but it is not significant if you don't go overboard with it. 1-3 subrequest won't be a problem at all.






          share|improve this answer













          I would create a menuFragment method in my DefaultController, and use a sub-request to render it.



          https://symfony.com/doc/current/templating/embedding_controllers.html



          Some people will tell you that sub requests slow down your code, but it is not significant if you don't go overboard with it. 1-3 subrequest won't be a problem at all.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 13:56









          Padam87Padam87

          886157




          886157













          • Hello, to go further than this answer, for menus have you tried KnpMenuBundle : symfony.com/doc/current/bundles/KnpMenuBundle/index.html

            – S. Bureau
            Nov 13 '18 at 14:02



















          • Hello, to go further than this answer, for menus have you tried KnpMenuBundle : symfony.com/doc/current/bundles/KnpMenuBundle/index.html

            – S. Bureau
            Nov 13 '18 at 14:02

















          Hello, to go further than this answer, for menus have you tried KnpMenuBundle : symfony.com/doc/current/bundles/KnpMenuBundle/index.html

          – S. Bureau
          Nov 13 '18 at 14:02





          Hello, to go further than this answer, for menus have you tried KnpMenuBundle : symfony.com/doc/current/bundles/KnpMenuBundle/index.html

          – S. Bureau
          Nov 13 '18 at 14:02


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282507%2fsymfony-fixed-elements-on-the-page%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation