Conditional rendering liquid in Braze - css

I'm trying to change the color of a button depending which home country the user is from. But my rendering does not work/ does not override the current css. Is this line of code correct?
{% if {{custom_attribute.${home_country}}} == 'DE'%}
<div class="button-right btn btn-next" style="background:#992B82 !important;">
<a><p> NEXT</p></a>
</div>
{% else %}
<div class="button-right btn btn-next" style="background: #F1287E !important;">
<a><p> NEXT</p></a>
</div>
{% endif %}
If anyone is familiar with Braze, liquid conditional rendering, and if it is possible. Im grateful for any answers!

Related

Omines Datatables with Turbo and Stimulus

I am trying to use Turbo in a new Symfony development. I'm following Turbo: Drive, Frames & Streams as a reference! and previously Symfony UX: Stimulus. Both topics are new to me and as if that weren't enough, I don't have much experience with Javascript.
All good except that I have not been able to get Omines Datatables to work under this scheme. I understand that I must create a Stimulus component but I have not achieved even the most basic thing, which is to load the Datatable.
I wonder if someone can guide me or if they have gone through the same thing, maybe they can provide a practical example of how to do it. Is it too much to ask?
In general, I usually load the Datatables in the following way:
{% block body %}
...
<div class="row">
<div class="col-12">
<div id="app_provinciaList">
<div class="d-flex justify-content-center">
<div class="spinner-border m-5" role="status">
<span class="sr-only">Cargando...</span>
</div>
</div>
</div>
</div>
</div>
...
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script>
$(function () {
var grillaApp_provincias = $('#app_provinciaList').initDataTables( {{ datatable_settings(datatable) }}, {
searching: true,
}).then(function (dt) {
dt.on('init', function(settings, json) {
$('#dt_filter input').attr("placeholder", "Provincia...");
$('#dt_filter input').width(300);
});
});
});
</script>
{% endblock %}

Flask-WTForms .validate_on_submit() never executes

So basically I want to have a Updateform() form that allows users to update their account details. All my other forms (register, etc.) work perfectly fine but this specific form never validates on submit. Hence when I press the submit button the page just refreshes but the .validate_on_submit() code doesn't execute.
I've looked through the forums and a common issue I found is the .CSRF token missing, but I'm using form.hidden_tag() which I read should work perfectly fine. So it seems that my issue is unique.
I've been looking on the forums for hours but haven't found a solution.
Here is my form code:
class Updateform(FlaskForm):
email = StringField('Email:', validators=[DataRequired(), Email()])
picture = FileField('Update Profile Picture:', validators=[FileAllowed(['jpg', 'png'])])
submit = SubmitField("Update")
def validate_email(self, email):
if email.data != User.email:
if User.query.filter_by(email=email.data).first():
raise ValidationError('Email has already been registered')
Here is the route:
#users.route('/account', methods=['GET', 'POST'])
#login_required
def account():
form = Updateform()
print("hello")
if form.validate_on_submit():
print(form)
print("YES!!!")
name = current_user.name
pic = add_profile_pic(form.picture.data, name)
current_user.profile_image = pic
current_user.email = form.email.data
db.session.commit()
flash("Account Updated")
# elif request.method == "GET":
# form.email = current_user.email
profile_image = url_for('static', filename='profile_pics/'+current_user.profile_image)
return render_template('account.html', profile_image=profile_image, form=form)
And here is the html code:
{% extends "base.html" %}
{% block content %}
<div align="center">
Hi {{ current_user.name }}<br>
<img align="center" src="{{ url_for('static', filename='profile_pics/'+current_user.profile_image) }}">
</div>
<div class="container">
<form method="post">
{{ form.hidden_tag() }}
<div class="form-group">
{{ form.email.label(class='form-group') }}
{{ form.email(class='form-control') }}
</div>
<div class="form-group">
{{ form.picture.label(class='form-group') }}
{{ form.picture(class='form-control') }}
</div>
<div class="form-group">
{{ form.submit() }}
</div>
</form>
</div>
{% endblock %}
The extra classes you see are from the bootstrap library incase anyone is wondering.
Hello you could find out what the problem is by adding a else for you if form.validate_on_submit(): and have it do this
for error in form.email.errors:
print(error)
for error in form.picture.errors:
print(error)
this should tell you what is not working hope this helps and I have not tested this so it could have typos

Drupal 8 - reach node/content needed variables in view

New user of D8 : my problem is to access to fields in a view or even in general with Drupal 8.
As we could do with ACF in Wordpress.
a {{ kint() }} crash my chrome but works with Firefox to explore the content var.
Unfortunately I do not managed to find and use fields' variables in my view.
I create a new view, which actually display the last three articles. These are well displayed in ugly list but I want to extract fields to put them in a custom html integration.
I create and use a new template for the view :
x node--view--liste-des-actualites--page-2.html.twig
In a custom parent :
x node--page-accueil.html.twig
But when I try to kint() content in my node--view--liste-des-actualites--page-2.html.twig, I have the custom field of the page (Page accueil) and can't find the article's one.
I managed to do it in my custom page but not in this view.
{%
set classes = [
'node',
'node--type-' ~ node.bundle|clean_class,
node.isPromoted() ? 'node--promoted',
node.isSticky() ? 'node--sticky',
not node.isPublished() ? 'node--unpublished',
view_mode ? 'node--view-mode-' ~ view_mode|clean_class,
'clearfix',
]
%}
{{ attach_library('classy/node') }}
<article{{ attributes.addClass(classes) }}>
<div{{ content_attributes.addClass('node__content', 'clearfix') }}>
{{ content }}
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<a href="{{ LINK_VAR }}" class="bloc-type">
<div class="categ categ_projet">{{ CATEGORY_VAR }}</div>
<div class="img"> <img src="{{ IMAGESRC_VAR }}" alt=""> </div>
<span class="wrapper">
<p class="date">{{ DATE_VAR }}</p>
<h3>{{ TITLE_VAR }}</h3>
</span>
</a>
</div>
</div>
</article>
EDIT
I managed to guess some fields but this is definitely not a good way to find variables..
{{ node.label }} + {{ content.field_tags }} (But I do not want a rendered one, I just want the text/value)
if you use kint(); to debug large arrays can crash your browser.
I would suggest to use the devel module https://www.drupal.org/project/devel. With devel you can debug your arrays inside of the Drupal8 UI for each content type, block or view.
In my case i use the UI of devel (additional tab on each content). in the module settings, you can chose how devel debugs, the error handling and the output.
As the OP commented it is possible to use a preprocess to display the array on your site:
function <themename>_preprocess_page(&$variables) {
dpm($variables);
}

Twig -Set variable as value

I have this piece of code inside Twig loops that will render beautiful color to every first letter of key=>value
<i class="avatar avatar-color-95 avatar-letter-c">{{ firstletter(message.firstname)}}</i>
But I want this to display color in dynamic way, different colors depending the length of the value
{% for message in pagination %}
{% set namecount = message.firstname | length %}
{#{ dump(namecount)}#}//outputs number(length)
<div class="container avatar">
<i class="avatar avatar-color-12 avatar-letter-c">{{ firstletter(message.firstname)}}</i>
{% endfor %}
I want to do it like this
<i class="avatar avatar-color-{{ namecount }} avatar-letter-{{firstletter(message.firstname)}}">
How do you do it? I tried to put qoutes between
"{{namecount}}"
and
"{{firstletter(message.firstname)}}
But it doesnt work. I cant find any docs for this in Twig docs,.How do you do it?
From the comments section...
You could just use <i class="avatar avatar-color-{{ message.firstname|length }} avatar-letter-{{ message.firstname|slice(0, 2) }}">.
Unless you are going to be using the variable again there's not much point in setting a variable rather than calling the filter/function inline.

Liquid adding red boxes around html rendering

I am trying to render some Angular2 code using Jekyll and Liquid. Here's what I start with
{% highlight html %}
<button (click)="action('dec')">Decrement</button>
<span>{% raw %}{{count}}{% endraw %}</span>
<button (click)="action('inc')">Increment</button>
{% endhighlight %}
And this is what I get
The red squares have been added automatically. How do I remove them?
In your _sass/_syntax-highlighting.scss remove styles for the .err class
.err {} // Error

Resources