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

  • SEARCH
  • Home
  • 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 8916533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:15:43+00:00 2026-06-15T05:15:43+00:00

How button_primary macro can call button macro in Twig engine? I’ve tried this solution,

  • 0

How button_primary macro can call button macro in Twig engine? I’ve tried
this solution, but it doesn’t work, it says that the function “button” does not exist:

{% macro button(label, type, size) %}
    {% set type = type|default('default') %}
    {% set size = size|default('large') %}
    {% set cls = ['btn'] %}

    <a href="#" class="{{ cls|join(' ') }}">{{ label }}</a>
{% endmacro %}

{% macro button_primary(label, size) %}
    {{ button(label, 'primary', size) }}
{% endmacro %}
  • 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-15T05:15:44+00:00Added an answer on June 15, 2026 at 5:15 am

    EDIT: As per cr4zydeejay’s answer Feb 7th 2021 the answer was updated to reflect the correct way in Twig 3.x

    Twig 3.x

    https://twig.symfony.com/doc/3.x/tags/macro.html

    When macro usages and definitions are in the same template, you don’t
    need to import the macros as they are automatically available under
    the special _self variable:

        <p>{{ _self.input('password', '', 'password') }}</p>
    
        {% macro input(name, value, type = "text", size = 20) %}
            <input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}"/>
        {% endmacro %}
    

    Twig 2.x

    Unfortunatly Gremo’s answer works, but is not the right way to do it.

    When you define a macro in the template where you are going to use it, you might be tempted to call the macro directly via _self.input() instead of importing it; even if seems to work, this is just a side-effect of the current implementation and it won’t work anymore in Twig 2.x.

    http://twig.sensiolabs.org/doc/tags/macro.html

    Correct way:

        {% macro input(name, value, type, size) %}
            <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
        {% endmacro %}
        
        {% macro wrapped_input(name, value, type, size) %}
            {% import _self as forms %}
        
            <div class="field">
                {{ forms.input(name, value, type, size) }}
            </div>
        {% endmacro %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can define icon for a jquery ui button in code like this; $(
I've this button $('#galery .buttonClose').button({ icons: { primary: ui-icon-closethick, text: false } }); css
In button click event I am writing this code.(code behind).I know button click event
Based on the jquery ui button documentation, I tried the following: <jquery>$(#test).button({ icons: {
I have a jQuery UI Button that I'm placing in a jqGrid toolbar but
I have the following problem with this code: <button id=delete>Remove items</button> $(#delete).button({ icons: {
I am trying to display a button with image only on my page but
This is my div in the aspx page: <div id=pop-up> <button id=btnClose>Close</button> <div id=mopopuptitle>
$(#slideshowadvanceconfig).button({ icons:{ primary: 'ui-icon-circle-arrow-e'} }).toggle(function () { $(this).button(option, { icons: { primary: 'ui-icon-circle-arrow-s'} });
This is my ajax function and $('#save_form_3').button({ icons: { primary: ui-icon-disk } }) .click(function

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.