Creating Title String in sitefinity - sitefinity-4

I am trying to create a unique title in sitefinity, the current title is something like this: "Chicken Sandwich". This is the code that is creating the title:
Page.Title = (this._Product.PageTitle != "" ) ? this._Product.PageTitle : this._Product.Name;
I want to title to be something like this "Nutritional Information for Chicken Sandwich".

In Sitefinity 4/5 you kind of have 2 different titles. The first one is the 'name' of the page, the second is the Title for search engines. The name is seen throughout the backend of Sitefinity and is used in the navigation widgets. See screenshot here
You can retrieve both by the following statements:
string shorttitle = new PageManager().GetPageNode(new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key)).Title;
and
string longtitle = new PageManager().GetPageNode(new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key)).Page.HtmlTitle;
Hope it helps!
Jochem

Related

How to convert CodeIgniter urls into user friendly ones?

I've explored lot of questions and articles regarding this but I can't find how to get this done.
I'm doing a website which provides specifications of several products such as phones, tablets, tv etc. Here's what I've:
Controller - Specs (create and display specification of all products)
Method - Display (fetches detailed specs of selected model and shows)
Method - Index (lists names of all models stored in the table. this is where I build anchor links)
Display method takes three arguments (1, 2, 3).
1 - Type of product (Phones, Tablets, TV etc)
2 - Model Slug (iphone-6, galaxy-tab-s3, bravia-kdl-50w800d etc)
3 - Model ID (1, 4, 13 etc)
My URLs right now are like this:
localhost/sitename/specs/display/phones/iphone-6/1
localhost/sitename/specs/display/tablets/galaxy-tab-s3/4
localhost/sitename/specs/display/tv/bravia-kdl-50w800d/13
What I want to achieve is URLs which are like this:
localhost/sitename/iphone-6
localhost/sitename/galaxy-tab-s3
localhost/sitename/bravia-kdl-50w800d
I don't mind restructuring my tables/controllers/methods or anything else if this can be achieved using whatever.
Thanks for reading.
Edit:
Route.php
$route['default_controller'] = 'Specs/index';
$route['404_override'] = 'Errors/show_404';
$route['translate_uri_dashes'] = FALSE;
This is how I'm building the anchor links (view_file->index.php, called from Index method):
<?php
foreach model(in the table)
echo anchor(specs_controller.display_function.product_type.model_slug.model_id, model_name);
end foreach
?>
I can get the desired URLs with following code in route.php. Only problem is I'm not able to make the 'urlController/urlMethod' return a value in the function which can be assigned to $result variable.
$route['(:any)'] = function ($1)
{
$result = 'urlController/urlMethod/'.$1;
return $result;
};
I'm not sure how to do this. Can someone suggest how I should call 'urlController/urlMethod'?
You could achieve it with CodeIgniter URI Routing. Considering
localhost/sitename/galaxy-tab-s3
maps to
localhost/sitename/specs/display/tablets/galaxy-tab-s3/4
And, model id i.e 4, in this case, is static with respect to galaxy tab s3, as you have not mentioned any such Id in the simplified URL.
My understanding is with every URL localhost/sitename/iphone-6, you need three details about the string 'iphone-6'. i.e. type of product, model-slug, model id. One way could be write something like
$route['sitename/(:any)'] = 'routingController/commonRoutingMethod/$1';
Here, create a new routingController and write some logic into commonRoutingMethod() method, which takes the string like iphone-6 and fetches its all three details i.e. product type, model id etc. And then redirects by building the exact URL using
header('Location: http://localhost/sitename/specs/display/$productType/$modelSlug/$modelId/');
NOTE : There could be more forward ways just using regex match in routes.php, given that you create diffrentiated structure of the string, based on product type and model id e.g p_iphone-6_1 or t_galaxy-tab-s3_4.
Please use below routing code, to achieve it.
localhost/sitename/specs/display/phones/iphone-6/1
localhost/sitename/specs/display/tablets/galaxy-tab-s3/4
localhost/sitename/specs/display/tv/bravia-kdl-50w800d/13
localhost/sitename/iphone-6
localhost/sitename/galaxy-tab-s3
localhost/sitename/bravia-kdl-50w800d
$route['(:any)'] = 'specs/display/$1/$1/$1';
Let me know if you need any help.

Editing product page with dimsav/laravel-translatable

im using a package called Laravel-Translatable
but is giving me more problemns that i expect, mainly with quite simple tasks. For example i have a list of all records (products), and each of them haves 2 languages translated (en,es). But now i need to edit the product information to put in the inputs fields, and for this i wish in my edit page get all the translated details (title, description), but for some reason, is returning me only one language, it doesnt return all the translated details from a specific product:
ex: return Product::where('id', '2')->get();
Somebody uses this package?
Just read the documentation. Therein is all that you need.
Some example:
$product = Product::where('id', 2)->get();
$product->translate('de')->title = "Germany title";
$product->translateOrNew('pl')->title = "Polish title";
//Shortcut
$product->{'title:pl'} = 'lorem ipsum';
$product->save(); //It Will save all translations and main model

Django-nonrel sorting by foreignkey

Is there a way of returning items from a database in django-nonrel, using 'order_by' on a foreignkey?
Full details are as follows:
#Models.py
class Post(models.Model):
article = models.TextField(help_text='Paste or type HTML in here')
pub_date = models.DateField()
....
class TagItems(models.Model):
title = models.CharField(max_length=200)
....
class TagRel(models.Model):
the_post = models.ForeignKey('Post')
the_tag = models.ForeignKey('Tag')
TagRel defines a ManytoMany relationship between Post and TagItems classes.
I am wanting to get a list of articles for each tag.
#Desire output
My tag
-my first post
-my second post
My second tag
- my other post
- another post
All is good so far, as I use the following to filter the data:
def tagged_posts():
tag_items = TagItems.objects.all()
li =[]
for item in tag_items:
tag_rel_item = TagRel.objects.filter(the_tag__pk = item.pk)
li.append(tag_rel_item)
return {'list_of_objects': li}
I am using db-indexer to define the filter part of the query in db-indexes.py. All this works fine but I want to order my posts by publication dates.
Django docs tell me to use:
TagRel.objects.filter(the_tag__pk = item.pk).order_by('the_tag__pub_date')
But the order_by('the_tag__pub_date') part does not appear to be supported by django-nonrel.
The following also works in normal Django:
TagRel.objects.filter(the_tag__pk = item.pk).order_by('the_post')
This works because the Posts are already sorted by date in the model.
But this also does not appear to work in django-nonrel.
So my question is how do I return my posts ordered by date (latest>oldest)?
Thanks in advance
I'm taking a guess at this - you're using a ManyToManyField. I believe that's implemented using a ListProperty on App Engine's datastore.
See the section in the datastore documentation labeled "Properties With Multiple Values Can Have Surprising Behaviors":
http://code.google.com/appengine/docs/python/datastore/queries.html
That's most likely why your results appear unsorted. ManyToMany relations aren't supported natively in GAE. You'd probably have to sort them yourself after you get the results back.

Display categories

I have my website working on social engine, I have a Main page named as articles.tpl, and in that I have a sub-page named as article.tpl, article.tpl is used to show the entire article, and articles.tpl is used to show topics of articles not the content,
My concern is with articles.tpl(pretty confusing articles and article)
In articles.tpl, 3 articles title, author of article and date is displayed, but I also want to display the category of that article,
For that I tried the following code,
$article_category = "";
$parent_category = "";
$article_category_query = $database->database_query("SELECT articlecat_id, articlecat_title, ".
"articlecat_dependency FROM se_articlecats WHERE articlecat_id='".
$rc_article->article_info[article_articlecat_id]."' LIMIT 1");
if($database->database_num_rows($article_category_query) == 1) {
$article_category_info = $database->database_fetch_assoc($article_category_query);
$article_category = $article_category_info[articlecat_title];
if($article_category_info[articlecat_dependency] != 0) {
$parent_category = $database->database_fetch_assoc(
$database->database_query("SELECT articlecat_id, articlecat_title".
" FROM se_articlecats WHERE articlecat_id='".
$article_category_info[articlecat_dependency]."' LIMIT 1"));
}
}
$smarty->assign('article_category', $article_category);
and in articles.tpl file I called it in this way
<span class="tahoma11_blue">| {$article_category}</span>
But when I check I get nothing, that space is blank, I am just able to see
|
How can I display the category?
i think you have to change
$smarty->assign('categories', $categories);
to
$smarty->assign('article_category', $article_category);
(in your example, you assign the (apparently empty) php variable $categories to the smarty variable categories. then, in the template, you use a smarty variable article_category - which never got assigned)

Grails: can remoteField update multiple fields?

Assume i have a book entity with an isbn field.
When entered a isbn number, i want 2 fields to be updated: title and author.
My controller looks like this:
def ajaxGetBook = {
def book = Book.findByIsbn(params.isbn)
if(book==null) book = new Book()
render book as JSON
}
So my call works, and i get a full JSON Book.
Now i would like to update 2 texfields by the update attribute
<g:remoteField action="ajaxGetBook" update="title" name="isbn" value="${bookInstance?.book?.isbn}" paramName="isbn"/>
Now the title field gets updated with the full book object, so that doesn't work.
Is it possible to update field title with only the JSON book.title?
Is it possible to update more fields at once?
I could render book.title as JSON but that works for only one field.
Thank you
Well, the g:remoteField tag is explicitly for one field, so you can't use it to update more than one. So, you're left with 2 easy choices:
Use 2 g:remoteField calls... this isn't a bad option, as they would happen in near parallel, as they are Async calls.
Roll your own Ajax. use g:remoteFunction instead, and have the JS function that you place in the "success" attribute take your book, and update the appropriate HTML fields.

Resources