Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:29:06+00:00 2026-06-07T04:29:06+00:00

I need to show a value at the top of a page, which needs

  • 0

I need to show a value at the top of a page, which needs to be updated after I have run some Twig loops in the middle of the page.

Here’s an example:

<div>Total Amount: {{ totalAmount }}</div>
{% for product in products %}
    {% set totalAmount = totalAmount + product.amount %}
{% endfor %}

I could compute the value in the Symfony controller, but there are certain reasons why I would prefer doing this in the Twig template.

Is the above possible with Twig? I’m sure the Twig code is executed sequentially and I may have to find a different solution. But I’d like to see if anyone has any suggestions.

Thanks,

JB

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:29:08+00:00Added an answer on June 7, 2026 at 4:29 am

    Use blocks.

    In your main template (layout):

    <div>Total Amount: {% block totalAmount %}{% endblock %}</div>
    

    In your child template:

    {% for product in products %}
        {% set totalAmount = totalAmount + product.amount %}
    {% endfor %}
    
    {% block totalAmount %}{{ totalAmount }}{% endblock %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JavaScript where I need to hide (and eventually show) some text
I have a <select multiple='multiple' and I need to show the selected value in
I have a div that is fixed at the top of the page, which
I need to show an integer value in a TextBox in my C# Windows
I need to show for every link, dynamically some text with Java-Script (jQuery). The
I need to show more than one report on a Page like Classic Report,
I need some help here, I'm currently going round in circles. I have a
I have one HTML page with one toggle button and some drop down item.
I'm making a page which is meant to show 4 objects at the same
I have a div,I need to show this div on the center of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.