I hope somebody here is using CMSMS and will help me with a piece of advice.
I've been struggling for two days to find an answer. I'm quite new to this cms.
I need a two column form - half in left div and the other half in the right div.
The question is how do I arrange items (input + labels) with a specific class using smarty templates?
I've tried something like this:
{if $entry->css_class=='formgroup-right'}
<div class="right-side">
...............
</div>
{/if}
but it doesn't include all divs into one. I need to just modify the default formbuilder template. I need a pattern. I don't know if it's possible at all to do this using smarty.
{if $entry->css_class=='formgroup-right'} // if entry css class is equal to formgroup-right then include all of them into div.right-side
<div class="right-side">
{foreach from=$fields item=entry}
{if $entry->display == 1}
{strip}
{if $entry->needs_div == 1}
<div
{if $entry->required == 1 || $entry->css_class != ''} class="
{if $entry->required == 1}
required
{/if}
{if $entry->required == 1 && $entry->css_class != ''} {/if}
{if $entry->css_class != ''}
{$entry->css_class}
{/if}
"
{/if}
>
{/if}
.................................................
{/if}
{/foreach}
</div>
{/if}
Well you are a little vague here but if all you want is all inputs with class formgroup-right in a
<div class="right-side"> ... </div>
and all with class formgroup-left in a
<div class="left-side"> ... </div>
First arrange all fields for left together and all for right together
100 field A -left side
102 field C -left side
104 field E -left side give this class last-left
101 field B -right side
103 field D -right side
104 field F -right side
Then in your form template
{assign var=side value=0}
<div class="left-side">
{foreach from=$fields item=entry}
{if $entry->display == 1}
...................
{if $entry->css_class == 'last-left'}
</div> <!-- end of left side -->
<div class="right-side">
{/if}
{/if}
{/foreach}
</div> <!-- end of right side -->
This will go through the fields in the order you have arranged them and place the first fields in the left side div until it get to the last when it will close the div and open the right div.
That is if I understand your problem.
Related
I'm trying to perform an action based on the results of an earlier assertion. I have the following situation, I want to determine the number of versions for a document, this is represented in the follwing html:
<ul data-testhook-id="accordion-body">
<li data-testhook-id="accordion-body-item">
<div>
<div data-testhook-id="version-1">
<div data-testhook-id="avatar">
<div data-id="tooltip">John Doe</div>
</div>
</div>
<span data-testhook-id="content">1. 17-08-2018 at 15:26</span>
</div>
<div data-testhook-id="version-2">
<div data-testhook-id="avatar">
<div data-id="tooltip">John Doe</div>
</div>
</div>
<span data-testhook-id="content">2. 20-08-2018 at 13:05</span>
</div>
<div data-testhook-id="version-3">
<div data-testhook-id="avatar">
<div data-id="tooltip">Jane Doe</div>
</div>
</div>
<span data-testhook-id="content">3. 20-08-2018 at 13:11</span>
</div>
<div data-testhook-id="version-4">
<div data-testhook-id="avatar">
<div data-id="tooltip">No Body</div>
</div>
</div>
<span data-testhook-id="content">4. 21-08-2018 at 13:11</span>
</div>
<svg width="12" height="12" data-testhook-id="icon-active-version"><path d="path-here"></path></svg>
</div>
</div>
</li>
Each element with test id data-testhook-id="version-xxx" is a line containing version information and its these div elements I want to count. for this I have set up the following:
cy.get('[data-testhook-id="accordion-body-item"] > div > div').its('length').as('versions')
Now if I add the following assertion, this passes without any problem
cy.get('#versions').should('equal', 4)
But if I try to use the outcome of the number of div's found as a variable in a console.log I no longer get '4' but [object, Object]. Tried this by:
var size = cy.get('[data-testhook-id="asset-versions"] [data-testhook-id="accordion-body-item"] > div > div').its('length')
console.log('foo ' + size)
Which results in foo [object Object] being printed to the console.
What I want to do is use the number of items in a selector to select an element, like:
cy.get('[data-testhook-id="accordion-body-item"] > div > div:nth-child(' + size + ')').find('svg').should('have.attr', 'data-testhook-id', 'icon-active-version')
But as the var is not a number I get the msg
Error: Syntax error, unrecognized expression: :nth-child
[data-testhook-id="asset-versions"] [data-testhook-id="accordion-body-item"] > div > div:nth-child([object Object])
Is it possible to use the number of elements found as a variable for a next selector?
Try this:
cy.get('[data-testhook-id="accordion-body-item"] > div > div').its('length').then((size) => {
cy.get('[data-testhook-id="accordion-body-item"] > div > div:nth-child(' + size + ')').find('svg').should('have.attr', 'data-testhook-id', 'icon-active-version')
});
You cannot assign or work with the return values of any Cypress command. Commands are enqueued and run asynchronously. What commands really return are Chainable<typeOfValueYouWant>, in another words, it's kind of queue object which resolves with desired value.
Read more here
BTW: I think you should consider change your approach for selecting elements. Read more here.
For those who are using Typescript - I wrote plugin for tslint which prevents making this mistake: https://github.com/krzysztof-grzybek/tslint-plugin-cypress
I'm creating a tag system on my website. So far it's all working great. But now I wish to create a page that shows all my tags under their own tab like you have with a portfolio page.
Example: http://www.don-zalmrol.be/tags?tag=Electronics
My page already displays the tags for a specific tag under it's own tab (i.e. electronics), but as you might guess I wish to populate the other tags in their respective tab as well.
So in short you land a view that displays the tag you've selected, but on the same page you can see the others as well.
Anybody has any idea how I can do this? I don't think I'm far away from the solution as I can already load the projects for specific tags under it's own tab. Now I only need to populate the remaining tabs with the tags!
Thanks!
This is my code so far:
http://pastebin.com/jwGW0NKZ
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
var portfolio = Umbraco.TagQuery.GetAllContentTags().OrderBy(t => t.Text);
var tagList = Umbraco.TagQuery.GetAllContentTags().OrderBy(t => t.Text);
string tag = Request.QueryString["tag"];
if (!tag.IsNullOrWhiteSpace())
{
var publishedContent = Umbraco.TagQuery.GetContentByTag(tag);
if (publishedContent.Count() > 0)
{
#* Show title *#
<div class="media contact-info wow fadeInDown" data-wow-duration="1000ms" data-wow-delay="600ms">
<center>
<div>
<i class="fa fa-tags"></i>
</div>
<br />
<div class="media-body">
<h2>Tags</h2>
<p>Browse content by tag</p>
</div>
</center>
<br />
</div>
#* Show tag titles in tabs *#
<ul class="portfolio-filter text-center">
<li><a class="btn btn-default" href="#" data-filter="*">All tags</a></li>
#foreach (var tags in tagList)
{
<!-- Create a selected tag -->
if(#tags.Text == #tag)
{
<li><a class="btn btn-default active" href="#" data-filter=".#tag">#tag</a></li>
}
#* Show all other tags *#
else
{
<li><a class="btn btn-default" href="#" data-filter=".#tags.Text">#tags.Text</a></li>
}
}
</ul>
<div class="row">
<div class="portfolio-items">
#* Start picture content *#
#foreach (var tags in tagList)
{
#* Put selected tag in the right tag tab *#
if(#tags.Text == #tag)
{
#* Show tag content *#
foreach (var item in publishedContent.OrderByDescending(i => i.CreateDate))
{
<div class='portfolio-item #tag col-xs-12 col-sm-4 col-md-3'>
<div class="recent-work-wrap">
#* IF the project has a picture *#
#if(item.HasValue("pictureOfTheProject"))
{
var featureImage = Umbraco.TypedMedia((int)item.GetPropertyValue("pictureOfTheProject"));
<img class="img-responsive" src="#featureImage.GetCropUrl(250, 250)" alt='#item.GetPropertyValue("titleOfTheProject")' />
<div class="overlay">
<div class="recent-work-inner">
<h3>#item.GetPropertyValue("titleOfTheProject")</h3>
<a class="preview" href="#featureImage.GetCropUrl(250, 250)" rel="prettyPhoto">
<i class="fa fa-eye"></i> View
</a>
</div>
</div>
}
#* Else when the project doesnt have a picture, show default one *#
else
{
var noImage = "http://www.don-zalmrol.be/media/1440/no_image_available.png";
<img class="img-responsive" src="#noImage.GetCropUrl(250, 250)" alt="No image" />
<div class="overlay">
<div class="recent-work-inner">
<h3>#item.GetPropertyValue("titleOfTheProject")</h3>
<a class="preview" href="#noImage.GetCropUrl(250, 250)" rel="prettyPhoto">
<i class="fa fa-eye"></i> View
</a>
</div>
</div>
}
</div>
</div>
}
}
#* Put the other tags under there own tab *#
else
{
}
}
#* End dynamic tags *#
</div>
</div>
}
#* No content matching the tag? *#
else
{
<p>There isn't any content matching that tag.</p>
#Html.Partial("TagList")
}
}
#* Show the tag list with amount *#
else
{
#Html.Partial("TagList")
}
}
EDIT 27-03-2016
Ok so I now know that I need to play around with my tag query or use the IEnumerable. But I can't seem to find it out how I can do this without breaking the code...
#* Get all tags and order them by name *#
var tagList = Umbraco.TagQuery.GetAllContentTags().OrderBy(t => t.Text);
#* Get requested tag *#
string tag = Request.QueryString["tag"];
#* Show all content by requested tag *#
var publishedContent = Umbraco.TagQuery.GetContentByTag(tag);
Above are the pieces of code that list all the tags I have in a var, gets the name from the URL (i.e. Electronics) and one that then displays all content that matches said queried tag.
So in short I need to change the last part of the TagQuery to list all content that has a tag and then filter it out by the querystring to display them in their own category.
But how can list all tagcontent?
Cheers,
Don
Your issue is on line 76 of the pastebin where you loop through the published content, which is already filtered by the selected tag. Because of this, only content with the selected tag ever gets written to the template.
What you need to do is use the loop on line 70 where you're looping through all tags. The jQuery plugin you're using will handle the filtering by using the CSS class you add on line 78. You can get rid of the loop on line 76.
For clarity, I would also change the
#foreach (var tags in tagList)
to
#foreach (var item in tagList)
since the foreach is producing a single tag rather than plural "tags" as your code insinuates. This has the added bonus of allowing you to keep the rest of your code the same once you remove the loop on line 76.
I'm new to CMSMS and am using CGblog where I have a listing template and everything is working fine except that I need to stop an HR tag from displaying on the last item. Can't figure out the correct way to code this.
CMS Made Simple™ 1.11.10 “Pinzon”
{foreach from=$items item=entry}
<div class="CGBlogSummary">
<article>
<h3>{$entry->title|escape}</h3>
<p style="font-size: 12px;">{if $entry->author}Written by {$entry->author}{/if}{if $entry->postdate} on {$entry->postdate|cms_date_format}.{/if}</p>
<div class="row">
<div class="large-6 columns">
{if isset($entry->extra)}
<div class="CGBlogSummaryExtra">
{eval var=$entry->extra}
{ {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} }
</div>
{/if}
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="CGBlogSummaryField">
{if $field->type == 'file'}
<img src="{$entry->file_location}/{$field->value}"/>
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
</div>
<div class="large-6 columns">
{if $entry->summary}
{eval var=$entry->summary}
{else if $entry->content}
{eval var=$entry->content}
{/if}
<p>Read more...</p>
</div>
</div>
</article>
<hr /><!-- this should not be output on the final iteration of the loop-->
</div>
{/foreach}
You can simple change this line:
<hr /><!-- this should not be output on the final iteration of the loop-->
into
{if not $entry#last}<hr />{/if}
I believe you can use syntax as such:
<hr {if $entry#last} style='display:none' {/if} />
(hides the hr using css if its the last entry), quick and dirty though!
I'm new to CMSMS and taking an older installation through a painful upgrade path to get it to the current version. One of the major changes involves using Smarty 3 for it's templating engine. This change has broken a couple of the existing templates.
The related CMSMS module is called "Product and Inventory Manager" which looks like it's part of "Calguys Module Extensions"
Here's the error message I'm getting:
Syntax Error in template "module_db_tpl:ProductsWithLocation;summary_default" on line 26 "<h2 style="float:left;margin-right:10px;color:"#fff">{$products_path_names.$key parent=$tmp|ltrim:'-1'}</h2>" unexpected "parent" attribute
Here's the entire template that's throwing it:
{if !isset($items)}
{cgerror}<h2>Sorry! There is No material matched the query</h2>{/cgerror}
<p>Please try browsing our "full catalog" here. </p>
{else}
{if empty($products_path_names)}
{assign var='products_pagelimit' value=$actionparams.pagelimit|default:'25'}
{assign var='products_parent' value=$actionparams.hierarchyid|default:$actionparams.parent}
{assign var='products_hier_info' value=$ProductsWithLocation->GetHierarchyInfo($products_parent)}
{assign var='products_path_ids' value='.'|explode:$products_hier_info.hierarchy}
{assign var='products_path_names' value=' | '|explode:$products_hier_info.long_name}
{if !empty($products_parent) }<div style="overflow:hidden">
<h2 style="float:left;margin-right:10px">Browsing </h2>
{foreach from=$products_path_ids key='key' item='tmp' }
{if !$smarty.foreach.default.last}
{module_action_link module='ProductsWithLocation' action='hierarchy' text=$products_path_names.$key page=$page_alias parent=$tmp|ltrim:'0' pagelimit=$products_pagelimit}
{else}
<h2 style="float:left;margin-right:10px;color:"#fff">{$products_path_names.$key parent=$tmp|ltrim:'-1'}</h2>
{/if}
{/foreach}<h2 style="float:left"> Colors...</h2></div>
{/if}
{/if}
<div id="status-bar"
{if isset($pagecount) && $pagecount gt 1}
<span class="page-text">{$curpage} {$oftext} {$pagecount} {$pagetext} </span>
<ul class="paging">
<li>{$firstlink}</li><li>{$prevlink}</li> <li>{$nextlink}</li><li>{$lastlink}</li></ul>
{/if}
Switch Thumb
{if $products_parent !=13 }
<a class="a-z" href="{$products_path_names.$key}_Index.htm">{$products_path_names.$key}</a>
{else}
{/if}
</div>
<ul class="gallery">
{foreach from=$items item=entry}
{*
the summary template has access to custom fields via the $entry->fields hash
and to categories via the $entry->categories array of objects. Also
attribute information is available via $entry->attributes.
you should use the get_template_vars and the print_r modifier to see
what is available
*}
{if $products_parent == 13 }
<li>
<dl>
<dt><a class="tip_trigger more-stone-info" href="{$entry->detail_url}">{$entry->product_name}<span class="tip">More information about <strong style="color:#9BD8EB">{$entry->product_name}</strong></span></a></dt>
{* accessing all of the fields in a list *}
{if isset($entry->fields)}
{foreach from=$entry->fields key='name' item='field'}
{if isset($field->value)}
{if $field->type == 'checkbox' or $field->type == 'image' && isset($field->thumbnail)}
{else}
{/if}
{if $field->type == 'image' && isset($field->thumbnail)}
<span class="tip">More information about <strong style="color:#9BD8EB">{$entry->product_name}</strong></span><img src="{$entry->file_location}/{$field->thumbnail}" alt="{$field->value}"/>
{/if}
{/if}
{/foreach}
{/if}
{assign var='hinfo' value=$ProductsWithLocation->GetHierarchyInfo($entry->hierarchy_id)}
<dd><em>Stone Type: </em>Cambria Quartz</dd>
<dd><em>Collection: </em>{module_action_link module=ProductsWithLocation action=default hierarchyid=$entry->hierarchy_id text=$hinfo.name}</dd>
</dl>
</li>
{else}
<li>
<dl>
<dt><a class="tip_trigger more-stone-info" href="{$entry->detail_url}">{$entry->product_name}<span class="tip">More information about <strong style="color:#9BD8EB">{$entry->product_name}</strong></span></a></dt>
{* accessing all of the fields in a list *}
{if isset($entry->fields)}
{foreach from=$entry->fields key='name' item='field'}
{if isset($field->value) && $field->name != 'GalleryFolder'}
{if $field->type == 'checkbox' or $field->type == 'image' && isset($field->thumbnail)}
{else}
<dd><em>
{$name}
</em>
{if is_array($field->value)}
{if !empty($field->value) }
{foreach from=$field->value item='val'}
{if $field->type == 'image' && isset($field->thumbnail)}
{else}
{module_action_link module=$mod->GetName() action=default fieldid=$field->id fieldval=$val text=$val} {/if}
{/foreach}
{/if}
{else}
{if $field->type == 'image' && isset($field->thumbnail)}
{else}
{module_action_link module=$mod->GetName() action=default fieldid=$field->id fieldval=$field->value text=$field->value} {/if}
{/if}
</dd>
{/if}
{if $field->type == 'image' && isset($field->thumbnail)}
<span class="tip">More information about <strong style="color:#9BD8EB">{$entry->product_name}</strong></span><img src="{$entry->file_location}/{$field->thumbnail}" alt="{$field->value}"/>
{/if}
{/if}
{/foreach}
{/if}
{assign var='hinfo' value=$ProductsWithLocation->GetHierarchyInfo($entry->hierarchy_id)}
<dd><em>Stone Type: </em>{module_action_link module=ProductsWithLocation action=default hierarchyid=$entry->hierarchy_id text=$hinfo.name}</dd>
</dl>
</li>
{/if}
{/foreach}
</ul>{/if}
Here's the relevant snip of that template where the error occurs:
{$products_path_names.$key parent=$tmp|ltrim:'-1'}</h2>
From what I understand we're calling a custom function with a name based on products we have in our database. We're sending it an attribute "parent" which it's not expecting. If I remove that attribute the error goes away but the output gets weird.
Short of a magic bullet I think any clues where to look for this function being defined would help me. I'm also baffled by the use of what appears to be ltrim("-1") so any explanation of that would also be nice. Maybe I can replace this line with a longer if block to correct the function call?
Edit - Here's some sample values for the variables:
$products_path_names.$key holds string 'Granite'
$tmp holds string 00017
Thanks!
I more or less solved it. I got rid of the parent attribute entirely and fixed the weird output by changing this line:
{if !$smarty.foreach.default.last}
to
{if $smarty.foreach.default.last != ''}
It was not counting an empty string as false.
Seems to work now.
<div id = "board_code">
<div>
<span>r</span>
<span>o</span>
<span>w</span>
<span>1</span>
</div>
<div>
<span>r</span>
<span>o</span>
<span>w</span>
<span>2</span>
</div>
</div>
I am trying to get the string '2' to be used for comparison with char like { [ ( < ' "
I tried this:
alert($('#board_code > div').eq(1).eq(3).text();
output is: blank
When I tried this:
alert($('#board_code > div').eq(1).eq(0).text();
output is: row2
$("span").last().text()
That could work, but I'm not sure if it's good enough for your needs.
http://jsfiddle.net/6r2nP/1/
$("#board_code span").last().text()
That one might be better.
http://jsfiddle.net/6r2nP/2/