I have a conditional line of Razor code:
<BSCol MD="3" Class="d-flex justify-content-center"><b>#(_bid.PriceGuarantee ? "Price Is Guaranteed" : ((MarkupString)"<div class='text-danger'>Price Is NOT Guaranteed</div>"))</b></BSCol>
And it is rendering:
Related
I'm getting this super confusing Vue warning and I can't figure it out:
[Vue warn]: Property "me" was accessed during render but is not defined on instance.
at <UserReputation user= {reputation: {…}, _id: '638f81dbb288267e6340ddbc', username: 'artsborba'…} class="mt-1" >
...
Here on StackOverflow I can find more topics with this warning, but seems each one is a different case, and mine is just not making sense! My vue version is ^3.1.0, vuetify ^3.1.0 and vite ^2.5.4.
My component looks like:
// MyComponent.vue
<v-menu location="end" location-strategy="connected">
<template #activator="{ props }">
<div
v-bind="props"
class="user-info-container cursor-pointer"
>
<UserAvatar
:user="me"
/>
<div v-if="me" class="user-data">
<div class="username-row">
{{ me.username }}
<AppIcon
icon="downward-arrow"
color="primary"
class="user-menu-icon"
:class="{ 'is-active': props['aria-expanded'] === 'true' }"
/>
</div>
<!-- HERE WE HAVE THE WARNING SOURCE -->
<UserReputation :user="me" class="mt-1" />
</div>
</div>
</template>
...
</v-menu>
In the same component I have the me set as a prop:
props: {
me: {
validator: prop => typeof prop === 'object' || prop === null,
required: true
}
},
Now, please notice that in the same component I have another one using this me pro (<UserAvatar :user="me"...>), which doesn't trigger this warning. Only the <UserReputation... component usage does! If I comment out the <UserReputation... tag, the warning goes away.
I already tried placing this me as a computed value instead of a prop, directly inside MyComponent.vue (it comes from a Pinia store) and many other structures with no success. Hopefuly someone can help on this! Thanks in advance.
Maybe you are accesing at me property inside your UserReputation component, but in the parent you are passing me to user prop, like this :user="me", so... you need to access to user prop instead me prop inside UserReputation component.
If this answer doesn't resolve the question, please share us the structure of UserReputation component.
Is it possible to render a template, or even just a partial, from within the context passed to a top level template? It seems like this might require recursive rendering, but maybe I'm missing something.
The example below demonstrates this using Bootstrap.
Say this is my top level template:
<div class="panel">
<div class="panel-body">
{{{description}}}
</div>
</div>
And my context is:
{
description: "\
Some text before the warning.\
<div class=\"alert alert-warning\" role=\"alert\">\
<span class=\"glyphicon glyphicon-warning-sign\" aria-hidden=\"true\"> </span>\
My warning here.\
</div>\
Some text after the warning."
}
What I'd like to do is separate the alert into a partial for a number of reasons:
Arbitrary placement within surrounding text
Can make partials for types other than warning (danger, info, etc.)
Can add as many as needed interspersed in the context string
For these reasons, it seems like it's not possible to put it into the top level template.
The partial would look something like this:
<script id="partial-warning-template" type="text/x-handlebars-template">
<div class="alert alert-warning" role="alert">
<span class="glyphicon glyphicon-warning-sign" aria-hidden="true"> </span>
{{{warning-message}}}
</div>
</script>
Once this is in place, I would be able to use it like so:
{
description: "\
Some text before the warning.\
{{> partial-warning-template \"My warning here.\"}}\
Some text after the warning.\
{{> partial-warning-template \"Now adding a second warning.\"}}"
}
Maybe I'm missing something fundamental - is there a more idiomatic way of doing this?
You won't be able to include the partial blocks in the description value and expect them to be evaluated as partials by the top level template method; the entire description string will be spat out as a single literal string.
What you would need to do is to have the partials evaluated before you pass the context object with description to the top level template method.
If you have pre-compiled your partial in something like the following manner:
Handlebars.registerPartial('warn', Handlebars.compile(document.getElementById('partial-warning-template').innerHTML));
Then you will be able to call this partial when you construct your description string:
{
description: 'Some text before the warning.' +
Handlebars.partials.warn({ 'warning-message': 'My warning here.' }) +
'Some text after the warning.' +
Handlebars.partials.warn({ 'warning-message': 'Now adding a second warning.' })
}
How do i add some CSS to the Scala Helpers, and is it possible to remove the "Required" and "Numeric" text under the textfield?
#inputText(advForm("weeknr"))
#inputText(advForm("jaar"))
#inputText(advForm("datum"))
--------------------EDIT 1------------------
When I add my own CSS, im not getting the error warnings that i used to get when I try to upload an empty form, the text used to turn red. This is the code I changed
MyPlainFieldConstructor.scala.html(only 2 lines of code):
#(elements: helper.FieldElements)
#elements.input
advPlaatsen2.scala.html:
Added this line of code
#implicitField = #{ FieldConstructor(myPlainFieldConstructor.f) }
and this is how i placed the CSS(Foundation 5):
<div class="row collapse">
<div class="small-2 columns">
<span class="prefix">Email</span>
</div>
<div class="small-4 left columns">
#inputText(advForm("email"),
'id -> "right-label",
'placeholder -> "")
</div>
</div>
This way the forms looks how I want it to look but it doesnt show me errors and it doesnt even upload my files
but when i remove this line of code:(which is above the #import helper._)
#implicitField = #{ FieldConstructor(myPlainFieldConstructor.f) }
the form works as it should but looks really bad:
To customize the html and styles of a field you can write your own field constructor. Take a look to play docs here.
Code sample
'someproc' is a custom processor which extends org.broadleafcommerce.common.web.dialect.AbstractModelVariableModifierProcessor from broadleaf platform.
<myproc:someproc /> // as a result is objectCreatedInProcessor
<div th:classappend="${objectCreatedInProcessor==null?'null':'not_null'}></div>
<div th:classappend="${objectAddedToModelAndView==null?'null1':'not_null_1'}></div>
<div th:each="someVar : ${someVars}">
<div th:classappend="${objectCreatedInProcessor==null?'null':'not_null'}></div>
<div th:classappend="${objectAddedToModelAndView==null?'null1':'not_null_1'}></div>
</div>
<div th:classappend="${objectCreatedInProcessor==null?'null':'not_null'}></div>
<div th:classappend="${objectAddedToModelAndView==null?'null1':'not_null_1'}></div>
As a output result will be :
<div class='not_null'></div>
<div class='not_null_1'></div>
<div>
<div class='null'></div>
<div class='not_null_1'></div>
<div class='null'></div>
<div class='not_null_1'></div>
<div class='null'></div>
<div class='not_null_1'></div>
</div>
<div class='not_null'></div>
<div class='not_null_1'></div>
supposing we have three items into $someVars list.
The question is, why is $objectCreatedInProcessor beeing made NULL into th:each loop. And why variable $objectAddedToModelAndView isn't made NULL, and is accessible into th:each loop?
What I'm doing wrong? Is something what I miss?
EDIT1 : Closed conditional expression. This wasn't the reason of the problem, it was only a bad code sample.
EDIT2 : Closed classes into result display.
EDIT3 : Forogot to mention that $someVars is a variable added from a controller to spring ModelAndView.
It appears as if you are not properly closing the conditionals on your ternary functions. Add a } after the null and before the ? on each line.
Here is an example ternary from the docs for reference
'User is of type ' + (${user.isAdmin()} ? 'Administrator' : (${user.type} ?: 'Unknown'))
I am receiving the following error when trying to edit some of my Component Presentations using SiteEdit.
Sys.FormatException: Could not get the type info from component xml
schema. Field: cf_tcm:32-204267_title XPath:
Content/custom:Content/custom:title[1]
It's strange because some of the Components with the same Template work fine (these do not have an image set,but the ones with an image set do not work).
Here is the code for my CT:
<div class="column v-2 siteedit">
<!-- TemplateBeginIf cond = "Component.thumbnail" -->
<!-- TemplateBeginIf cond = "Component.image" -->
<a href="##Component.Fields.image##" class="fb ajax">
<!-- TemplateEndIf -->
<img src="##Component.Fields.thumbnail##" class="align-left"
alt="##thumbnail0.Metadata.alt##" height="69" width="99"/>
<!-- TemplateBeginIf cond = "Component.image" -->
</a>
<!-- TemplateEndIf -->
<!-- TemplateEndIf -->
<h2>
<tcdl:ComponentField name="title">##Component.Fields.title##</tcdl:ComponentField>
</h2>
<p>##Component.Fields.summary##</p>
</div>
(I have removed other editable fields just to make sure that it wasn't a problem with a specific field)
Any ideas?
Update
As requested here's my (anonymized) HTML, the 1st and 3rd components have the issue, the middle one is fine:
<div class="general-content columns-three">
<div class="column v-2 siteedit" style="height: 209px; ">
<!-- Start SiteEdit Component Presentation: {
"ID" : "97829119-68f0-4e41-9862-b042d480cb71",
"ComponentID" : "tcm:32-204859",
"ComponentTemplateID" : "tcm:32-204536-32",
"Version" : "2",
"IsQueryBased" : false
} -->
<a href="http://REDACTED:84/_images/REDACTED.png?__Proxy=0" class="fb ajax" target="_self">
<img src="/_images/REDACTED.gif" class="align-left" alt="REDACTED" height="69" width="99">
</a>
<h2>
<span style="">
<!-- Start SiteEdit Component Field: {
"ID" : "cf_tcm:32-204267_title",
"XPath" : "tcm:Content/custom:Content/custom:title[1]",
"IsMultiValued" : false
} -->REDACTED
</span>
</h2>
<p>REDACTED</p>
</div>
<div class="column v-2 siteedit" style="height: 209px; ">
<!-- Start SiteEdit Component Presentation: {
"ID" : "2933b5e0-2006-440d-bc03-2224650bdd7d",
"ComponentID" : "tcm:32-204268",
"ComponentTemplateID" : "tcm:32-204536-32",
"Version" : "5",
"IsQueryBased" : false
} -->
<h2> <span style="">
<!-- Start SiteEdit Component Field: {
"ID" : "cf_tcm:32-204268_title",
"XPath" : "tcm:Content/custom:Content/custom:title[1]",
"IsMultiValued" : false} -->REDACTED</span>
</h2>
<p>REDACTED</p>
</div>
<div class="column v-2 siteedit" style="height: 209px; ">
<!-- Start SiteEdit Component Presentation: {
"ID" : "fac3c467-7c71-4be9-b319-8a35524ee172",
"ComponentID" : "tcm:32-204860",
"ComponentTemplateID" : "tcm:32-204536-32",
"Version" : "2",
"IsQueryBased" : false
} -->
<a href="http://REDACTED:84/_images/REDACTED.png?__Proxy=0" class="fb ajax" target="_self">
<img src="/_images/REDACTED.gif" class="align-left" alt="REDACTED" height="69" width="99">
</a>
<h2> <span style="">
<!-- Start SiteEdit Component Field: {
"ID" : "cf_tcm:32-204269_title",
"XPath" : "tcm:Content/custom:Content/custom:title[1]",
"IsMultiValued" : false
} -->REDACTED</span>
</h2>
<p>REDACTED</p>
</div>
</div>
I explained when that error message appears here: "Could not get the type info from component xml schema" when loading a page in SiteEdit 2009
Your use-case may be different from that question, the product always shows this for the same reason: it can't find a field (that is identified in a <!-- Start SiteEdit Component Field command) in the current Component (that is identified in the enclosing <!-- Start SiteEdit Component Presentation command).
Given your error message:
cf_tcm:32-204267_title XPath: Content/custom:Content/custom:title[1]
It seems like Component tcm:32-204267 doesn't have a field named title.
In these cases it is always easiest if you look at the HTML that SiteEdit ends up processing, so what your staging/preview server returns. Find the title field and its enclosing Component Presentation and verify that indeed that Component Presentation has a field named title.
If you'd like a more direct answer to "what am I doing wrong?", add the relevant HTML-with-the-SiteEdit-commands to your question and I'll update my answer to match.
Update based on the HTML provided
If I look at the IDs of the Component and Fields you provided:
Component: tcm:32-204859 Field: cf_tcm:32-204267_title
Component: tcm:32-204268 Field: cf_tcm:32-204268_title
Component: tcm:32-204860 Field: cf_tcm:32-204269_title
The ID in the JSON is only used by SiteEdit to ensure some meaningless uniqueness. But in this case the Field ID seems to indicate from which Component the field comes.
If you then look at the data closely, you can see that for Component 2 the field points to the same Component. For Components 1 and 3 the fields actually point to another Component. Again, the ID properties of the Field commands are in themselves not used. But the relation between what works and what doesn't seems to coincide pretty well with the knowledge that SiteEdit loads the Schema of the Component indicated in the containing Component Presentation command and cannot find the field at the XPath indicated in the Component Field command.
I suspect that in #1 and #3 you have put some regular Component on the page, but are rendering the title of a Multimedia Component that is linked that Component. In #2 you are most likely rendering the title of an MMC that is explicitly put on the page.