Support Forum
Hey folks,
I have looked in every corner of the documentation and also the Twig docs and I cannot find anything in relations to the "href".
I have tried also "post." before my field name and also ".url" after that field (similar to using Views), but no luck.
Here is my markup:
<!-- Hero Block -->
<section class="hero-wrapper">
<div class="hero-inner">
<h1 class="hero-headline">
{{ hero_headline }}
</h1>
<h2 class="hero-header">
{{ hero_header }}
</h2>
<p class="hero-snippet">
{{ hero_snippet }}
</p>
<div class="hero-buttons">
<button class="hero-btn__primary">
<a href="{{ hero_button_1_url }}" title="{{ hero_button_1_text }}">{{ hero_button_1_text }}</a>
</button>
<button class="hero-btn__secondary">
<a href="{{ hero_button_2_url }}" title="{{ hero_button_2_text }}">{{ hero_button_2_text }}</a>
</button>
</div>
</div>
</section>
So my question, what is the syntax for my href when I have custom fields for my block?
Cheers
Hello,
I do not understand the question clearly, but I think the href markup in your code does not relate to Meta Box itself. Can you please let me know if the field value is outputted properly?
You can read more about <a>
tag with href here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
Hey Peter,
Sorry if it was confusing ... I know about href and anchor tags, what I am referring to is the Twig markup for the href.
In my code you can see I am using either {{ hero_button_1_url }} or {{ hero_button_2_url }} to reference the custom field name. As you can see they are using the button tag, so I have a custom field for the button name and also the button href (which is using the Page field.
In my example the front-end output breaks and it is caused by {{ hero_button_1_url }} or {{ hero_button_2_url }} within the href, so my code is not correct.
Hello,
So the issue is the field value is not outputted correctly, is that right? Can you please generate PHP code of the field group or you can export it to a JSON file and share it here? I will take a look.
Hey Peter,
Sorry, but I think you are not on the same page. I am not using PHP, I am using MB Blocks and rendering in the Code module, building it with HTML and Twig templating, so cannot generate any PHP code for you.
What I am simply asking is, what is the Twig syntax to use within a href when calling the Page Field?
Hello,
It's the generated PHP code from the field group that you create the MB Blocks, please follow the documentation https://docs.metabox.io/extensions/meta-box-builder/#getting-php-code
Sorry Peter, but again I am not sure what page you are on, but the link you provided has nothing to do with the issue or question that I asked.
I am NOT needing to generate PHP code to then apply to my functions file, as I would be deactivating the Met Box plugin.
I am NOT using PHP!!! I am using HTML and Twig -- NOT PHP!
I am creating a GUtenberg Block via the Custom Fields extension within Met Box AIO. I choose "Code" for the Rendering option, NOT PHP or a template, but code. I then type my own markup using standard HTML and Twig.
So again, the question I am asking (and it seems you don't have it) is, "What is the Twig syntax to put in the HREF so one can output the custom field value"???
If you can't answer the question, then please find someone who can. Thanks
Hello,
I understand that the field value is not outputted correctly on your site. So I ask to generate the PHP code from the field group or export it and share it here, then I can check the field settings ... to see what happens with the Twig code.
I do not tell you to use the PHP code to output the field value, please read the request carefully.