Sightly - Show the header tag only if there is a header - sightly

Using HTL (Sightly) I want to display
<h2 data-sly-text="${model.heading}"></h2>
But only if the ${model.heading} is not empty, otherwise nothing, not even the h2 tag.
I tried the following solution, but it didn't work:
<sly data-sly-test="${model.heading}"><h2 data-sly-text="${model.heading}"></h2></sly>

You can just write it as:
<h2 data-sly-test="${model.heading}" data-sly-text="${model.heading}">Heading placeholder</h2>
The snippet you posted should have worked too, since you did not mention what was not working I can suggest:
checking the model variable is properly defined and initialised
checking the heading property is properly exposed (either directly or via a getHeading method)

Related

Display raw text from custom field in Drupal

I'm trying to render a Block's Field as Plain Text as I need it used as part of HTML, I've tried using |RAW however I read it was unstable + it didn't work haha!
This is my existing HTML minified
Read More
However I would like to make it more useable
Read More
This would mean that when a user modifies the DrupalBlock HEX code it would change the color of the box. However the issues is when it's printed on the page it's looking like this
<div data-quickedit-field-id="#" class="field field--name-field-color field--type-string field--label-hidden field--item quickedit-field">FFFFFF</div>
the only thing I would like printed is "FFFFFF" with no div's
-
Here is my question: How do I display my Field_color as plain text when it prints?
You can use |raw : {{ content.field_color|raw }}.
If you need more information please ask.
I suggest you do a dump or kint of your content.field_color variable. You might be able to get some more information on it and get the answer!
Anyway, we have something similar in our project and the way we do it is by using a .getString() method.
{% set image_align = content.field_image_align['#items'][0].getString() %}
<div class="{{ image_align }}">
Our field is a list of values so you'll have to look for another array item to call the .getString() method on.

Angular not finding variable made by ng-repeat

I am using an AngularDart component in my webpage with the #Component. I can access variables inside the class by using the standard angular expressions in the html by using ng-model and {{}}. However when implementing a standard looping procedure:
<div ng-repeat="(x, y) in example_dictionary" ng-if="example_dictionary!=null">
{{x}}
</div>
This snippet gives me the strange error Class '~~~' has no instance getter 'x' (Class name snipped). The error is not wrong per-say. The class really does not contain any getter of x, but it shouldn't need to because the ng-repeat method is setting it and maintaining it.
For added entertainment, I replaced the {{x}} section with a static string I am looping and behold the loop command does in fact loop through the dictionary the proper amount. So the ng-repeat is not causing any problems with either looping or setting both of the non-pre-existing x and y variables.
The question: Why can't I access x and how can I access x?
That should work, but have you tried?
<div ng-repeat="entry in example_dictionary">
{{entry.x}}
</div>
After reducing the problem to a really simple size, I found out that removing the ng-if section of the div fixed the problem. How and why that even was a problem is beyond me. I now segregated the action of ng-if and ng-repeat into separate divs. I am not particularly happy with my findings, but it works.

Loosing special characters from Model property

I am using struts-2.3.16.3 for my application. My action implements the “ModelDriven” interface. Using interceptor reference as defaultStack.
The problem that i am facing is, all the special characters (non keyboard characters like ®, ℗) are disappearing from my model property by the time they reach to my action class. Other special characters like # # $ etc able to see those in my action.
Do i need to configure any other interceptors in the stack?. Help needed if i am missing in configuration.
Example: If i enter Piracy℗symbol in my text field, in action class when i print property value it shows Piracysymbol.
Thanks,
Ramesh
I think the problem is that you have not mentioned the content-type. Try putting
<%# page contentType=”text/html;charset=UTF-8″ %> tag in your code if you haven't already. If the problem still persists write your code like this
<s:text name="username"/> <s:property value="getText('username')"/>
Hope this helps.

Orchard - Wrappers for Fields

I'm trying to use a wrapper view for fields in a custom form but when I do the wrapper content shows up fine but I lose my field. I've looked over this tutorial on placement and I'm trying to use the wrapper functionality to get separators into my custom form to break up the questions but it's not working.
For example I've got a question on my form that asks for Name. in my placement file I have the following
<!-- content:2.[section].[questionNumber] -->
<Place Fields_Common_Text_Edit-Name="Content:2.1.1"/>
<Place Fields_Input_Edit-PhoneNumber="Content:2.1.2"/>
...
And this works fine, but I want to put a series of seperator headers between certain groups/sections of questions, for example this one is "General Information"
So I change my placement file's line for the Name to this...
<Place Fields_Common_Text_Edit-Name="Content:2.1.1;Wrapper=GeneralInfoHeader"/>
<Place Fields_Input_Edit-PhoneNumber="Content:2.1.2"/>
And this works perfectly, my header shows up , but now my question for Name is gone and my first visible question is for Phone Number. According to the tutorial I used, my wrapper view looks like this
<h3>General Information</h3>
<hr>
#Model.Html
But the line of #Model.Html doesn't actually output my field. How do I get the wrapper to work for Fields? (Orchard 1.6)
Well a wrapper is just a separate piece of Razor code that act like a parent of your view. So you need to tell them to display your content.
So you need to have #Display(Model.Metadata.ChildContent) in your wrapper to display the field itself.

pjax -- must links be inside the pjax-container?

I am using https://github.com/rails/pjax_rails.
I want to have my links inside a "permanent" portion of the page. I.e. in my layout I have
<%= link_to "Some Action", some_action_path %>
Then inside the view:
<div data-pjax-container>Content to be replaced</div>
Here is my javascript where I invoke pjax:
('[data-pjax-container]').pjax('a');
[You may note that this is different than the invocation method in the readme, but as a reported issue points out, the method in the readme doesn't work at all.]
This is not working (the link reloads the entire page).
If I move the link inside the div with the data-pjax-container attribute, it works (the page is not reloaded and only the container is updated).
I have not seen any examples where the link was actually outside of the container. Can anyone tell me how to get this to work?
I was probably focusing too much on the pjax-rails readme (not great). I went to the source (https://github.com/defunkt/jquery-pjax) which led me to changing my js to this:
$(document).pjax('a', '[data-pjax-container]')
..which got me back on the right track.

Resources