Redundant View Templates: 1 For Highlighting Searches, 1 For Browsing - layout

Currently I have 2 different templates to display a product: 1 for general browsing, 1 for search results. This is annoying, I have to manage 2 templates for what is more or less the same layout.
The reason, search results are highlighted. My highlight template looks like this, roughly:
for each result
<h2>
if search has name
<em> result.name </em>
else
result.name
end
</h2>
if search has price
<em> result.price </em>
else
...
end
...
end
I prefer not to creare a dummy search variable(s) just to use this view with the product's page. I considered building a "display" class that would be prepackaged with the appropriate ems but really this is more of the same, as my product browsing pages then have to unecessarily conform to this class.
I guess the argument can be made that they are 2 different views serving 2 different purposes, yet the fact that I have to manage 2 different files of the same HTML doesn't sit well with me.
Does anyone have a solution and/or take on this?

There can be various approaches to achieve this, for a specific solution please mention frameworks/platforms you are working with.
I can suggest following:
a) Split common layout and unique layout in different files and merge them as necessary. So you can have something like -
header.html
index.html
footer.html
search.html
Now index.html calls search.html as required. Quite scalable approach.
b) Javascript - You can dynamically generate dom elements on search pages using JS.

Related

Kentico Smart Search for application with multiple sites

I am having quite the difficulty. on our company site https://temp-quitlogixbase.quitlogix.org I had set up the Smart Search functionality. setting up indexes for each of the sites with in the application
(i.e.
https://colorado.quitlogix.org https://arkansas.quitlogix.orghttps://idaho.quitlogix.org
)
I even made sure to limit each site to the index meant for it. the problem is that the smart search results, either changes for each site, or if I include multipule indexes it gives me all the results for all the indexes, not just for the site I am working with. can some one help as to what I am doing wrong?
From your description, it sounds like you want each site's search to work independently so that - e.g. - Idaho results are not served on the Colorado search results.
To do this, you'll have (and sounds like you do) a SmartSearch index set up for each site with the allowed content in the index limited to the site in question.
What I would look at is the template your using for the search results. It looks very similar on the three sites you've listed, which makes me think that they are the same template. If that is the case and you're using a web part for the search results, you'll need a macro or some other logic to tell the page which index to look at.The template is effectively global, so each time you set the index on the Smart search results web part, it will override the previous value, even if you're switching between sites.
A way to do the switching can be to set the Indexes field to something like the following macro:
{% if (CurrentSite.CodeName == "QuitLogix_Arkansas") { "ArkansasSiteIndex" } else if(CurrentSite.CodeName == "QuitLogix_Colorado") { "ColoradoSiteIndex" } else {"IdahoSiteIndex"} #%}
If you've done all that or are using separate templates, you will not need that. Other options can include using multiple Smart search results web parts with their set the visibility based upon the current site or by having a different template for each sub-domain.

How to use PageLayout in a SharePoint Site?

I am kind of new to SharePoint. I am learning it on the go and learned about the concept of pagelayout and publishing features on the site. But I am not really 100% sure what is the difference between a WebPartPage, SitePage and PublishingPage. I kind of know what all these pages be used for, but what I not get is: why do they need to separate all these pages?
I think we can just get a publishing page and have all the feature there including webpart and everything else (with our choice of PageLayout). However I dont see a way to use a pagelayout on a particular SitePage.
Is there any particular reasons for using either one of them? Even though it seems like one of them can serve as all of them?
You should use page layout when ever you know the page structure. For example you are running an online news paper. You want to show the news to the users into three columns. First column is for menu, second column is for news content and third column is for advertisements. Now in your daily usage this layout is common. So you can use this page layout for entering the news. After creating the page layout you can make it as a default to your pages. Page layout is nothing but the structure of a page simply!!
A webpart page does not have a field for content directly on the page like a SitePage has. A Publishing Page is like a SitePage, but requires extra fields for dealing with the publishing extra features.
Using a single layout for all three risks being confused as to why one page does not work the same as another when it has the same layout (the difference would be the underlying features are different.).
I will make a comparison with cars. There are three type of cars, each is better suitable for a certain purpose: tractors for farming, buses for public transport, light cars for private transport. You could use a tractor for all the purposes above but it's not ideal.
"One of them can serve as all of them". This is not true in their current implementation. I'll give you one example: prefer Web part pages against Publishing pages to better control content added by contributors in an intranet. There are many other examples.

What will be the URLs of my expressionengine site, when using stash

I´m trying to understand how the use of the stash plugin will affect the URls of my site.
The traditional way:
I have a template group called site. Within the TG site I have the templates articles, about_us, etc.
The URl will for a single entry be
www.mysite.com/index.php/site/articles/title_of_respective_article
URL for the About-us-page:
www.mysite.com/index.php/site/about_us
Both will reflect the template_group/template structure and thus be SEO-friendly and give users a hint where they are on the site.
But when I use stash I will have 2 wrappers (one for the homepage and one for the rest of the site.
Partials will be used for header, main content and footer.
As far as I understand it, I´ll use the template_groups layout for the wrappers and partials for the main content.
The templating look like
Two wrappers build the TG "layout" Both are hidden, since they should´nt be called directly.
layout
.homepage
.site
Three partials in the TG partials
partials
header
main_content
footer
And by the way shouldn´t those not also be hidden, since they aren´t complete HTML-pages either.
This is what confuses me. How do I get my nice URLs back?
A URL like
www.mysite.com/index.php/site/about_us
will not match the TG/T concept anymore.
Any help?
To expand on both their answers above, and just to be specific to your www.mysite.com/index.php/site/about_us request:
You'd create a template group called "site" and then you may alternatively have something like this code in the /index template
{embed="layout/.site"}
{exp:channel:entries limit="1" disable="categories|member_data|pagination"}
{exp:stash:set name='title'}{title}{/exp:stash:set}
{exp:stash:set name='maincontent'}
<section>
<h1>{title}</h1>
<article>{content}</article>
</section
{/exp:stash:set}
{/exp:channel:entries}
The embed calls the .site layout and the interior simply pulls your specific channel:entries data.
As you can see, it's still using the traditional templategroup/template ways of building URLs, it's just pulling data differently.
When using Stash and the template partials approach (which I don't use personally), the files you mention are all embedded. You still use the same template groups and template files as before.
The Stash-based approach is simply a different way of doing things within your existing templates - not a replacement for them.
Exactly as Derek says. The way to think about it is this - with the template partials approach, your templates contain mostly (if not only) the entries logic (channel entries loop, its parameters, what custom fields are in play for that channel, etc). The outcome of the logic gets stores as stash variables. The stash variables then get called upon by your embedded layout templates to display the content you've stashed. So your URL structure remains the same, but you have considerably less duplication of effort since the more you constrain your templates to logic (i.e. very little if any formatting/display markup) the cleaner they are and the easier it then is to manage your templates.

How to embed blocks of data in ExpressionEngine without using many channels

I have used Drupal and think I'm doing it wrong with EE. I want to create many blocks of embedded User created entries in some of the templates, but don't want to have to create a channel for each one. In Drupal I could create a block specific to the client's needs, but I'm stumped on how to do this in EE.
For example, I have three different content areas on the home page, top/middle and bottom. Client doesn't want to roll out blog entries, they want specific content put in each one. The only way I see is I'd need to create three different channels and embed as such for top, changing channel to middle and bottom for each block. Is there a better way?
{exp:channel:entries channel="top" disable="categories|member_data|pagination" limit="1"
sort="desc" dynamic="no" }
Would I use category group and categories to do this? Meaning, I would create top, middle and bottom categories to call out those entries in my "home" channel?
For less than 1 hour of billable work, you'll get hundreds if not thousands of hours of effort packaged up for you to run with. Someone always pays for code, why not you this time? :)
The solution you have found does work - but I've found that ultimately it does not offer the flexibility needed by many clients.
I've used the following solution for many sites and clients have been pleased with it.
1) Define your block data as channels. For example I often have a Sidbar Ad, Sidebar Scripts, and Sidebar text channels.
2) Use a playa field-type (or another relational field-type) to create relationships from a parent entry (a page) to theses sub content types.
This normally looks something like this on the backend:
3) You can now use the parent entry to display the sub content. You'll of course need to pull all this data into your templates with something like the following:
<div id="right-side">
{exp:playa:children}
{if channel_short_name == 'sidebar_javascript'}
{cf_sidebar_js}
{/if}
{if channel_short_name == 'sidebar_videos'}
{exp:channel_videos:videos entry_id="{entry_id}" embed_width="300" embed_height="238"}
<h4>{title}</h4>
{video:embed_code}
<p class="caption">{video:title}</p>
{/exp:channel_videos:videos}
{/if}
{if channel_short_name == 'sidebar_ads'}
{exp:adman:show group="{cf_sidebar_adman_block}" order="RANDOM" limit="{cf_sidebar_adman_block_number_of}"}
<a href="{ad_url}" target="_blank">
<img src="{ad_image}" alt="{ad_alt}" />
</a>
{/exp:adman:show}
{/if}
{/exp:playa:children}
</div>
We generally make a channel called something like "general content" with a single field that can have any kind of native formatting (none or xhtml would mostly be used) and then use it for one-off bits that don't fit into other channels. It's hard for the client to find these entries in the CP for editing, so we make front-end "edit" links that open the correct entry in the CP and are visible only to member groups with content editing permissions.
This will only get hairy if you really need multiple customized fields for this use.
I have never used Low Variables, but I am under the impression that it could be useful here.
While I agree with the posters talking about the value of add-ons, this is a particular need that I have never had any problem solving natively. Besides the issue of the cost of add-ons (which IMO is worthwhile) you also add complexity to your installation the more software you add to it, making it more time consuming to troubleshoot bugs and to upgrade EE.

Can I use a Kentico macro to get a partial path?

I would like to know if it is possible to use kentico macros (not necessarily coding a custom one) to access part of the rewritten URL's Path.
Example: http://www.mysite.com/Category/Subcategory/
I would like to get the last part (Subcategory) so that I may then filter content dynamically. The reason I want to use the macro is to simply not have to have 20+ different page templates only so I can have different web part properties.
Assuming you are using Portal templates, and you don't want an 'all items in all subcategories' list on the parent:
Create an Article List web part on the parent page — parent to all the sub-categories.
Set the web part Path to /{0}/{1}/{2}/% (if your path was /Home/Parent/Subcategory for example) or something similar for your environment.
Use the default setting of Inherit for the page template for all subcategory pages.
This will not show anything on the parent page, and the sub-categories will show only the documents under themselves. Note: If you want the subcategory items to have their own views when user digs down to /{0}/{1}/{2}/item, you may need to filter by changing template inheritance, or Document Types on the web part, or something like that if you don't want the whole sub-category list to also show on the item-specific pages.
You can create a custom macro or, you can also use the string operations which are allowed within macros. Please see http://devnet.kentico.com/docs/6_0/devguide/available_macro_methods.htm#string_methods (and you can e.g. use the EndsWith or TrimStrart or something similar).
However, I think the best way would be to create a custom macro which will exactly fit. There might be some combination of macros and macro functions - but I think it is faster just to code a custom one which will cover your need 100%.
Also, you can take a look on the K# if there is something that will fit - http://devnet.kentico.com/docs/6_0/devguide/ksharp_syntax.htm

Resources