Problem Statement-
Assume predefined base templates and rendering are in place.
Want to create new template item using SPE.
Create Template Item using Template .
Update base template field using
Raw values. {Template Item GUID}|{Template Item GUID}
Create Standard
Values.
Add standard Layout rendering as raw values in standard ,
which is again available, just need to assign.
Add insert options.
Any guidance to go about this using SPE.
To create a template item with Standard Values in Sitecore with Sitecore PowerShell Extensions (SPE).
You can use some things like this:
cd master:\
$item = New-Item -Path "/sitecore/templates/User Defined" -Name "testtemplate" -type "{AB86861A-6030-46C5-B394-E8F99E8B87DB}"
$standardvalues = New-Item -Parent $item -Name "__Standard Values" -type $item.ID
$item.Editing.BeginEdit()
$item["__Standard values"] = $standardvalues.ID
$item.Editing.EndEdit()
I suspect that the insert options can add the same as the __Standard Values just edit the Insert options field. See also Set-Layout and Add-Rendering for adding renderings.
Related
For some reason the placeholder key for a large number of pages changed I need to change it back. The problem is we use dynamic place holders so parts of the placeholder key are random GUIDs and they are in every sublayouts placeholder key
So I need
/bacontent/../baproducttabscaffold{6e0244e2-3583-47cb-b575-0bc920186d42}
to be
/bacontent/../baproducttabscaffold{895ecd6f-4abb-478d-9dad-88e5e05b8c30}
What would be the most efficient way of changing these?
What I ended up doing is using Sitecore Powershell Extensions
https://marketplace.sitecore.net/en/Modules/Sitecore_PowerShell_console.aspx
The script I used
$pages = gci -Path "master:\my path" -Recurse
$oldGuid = "6e0244e2-3583-47cb-b575-0bc920186d42"
$newGuid = "895ecd6f-4abb-478d-9dad-88e5e05b8c30"
foreach($page in $pages){
$oldRenderings = $page.__Renderings
$newRenderings = $oldRenderings.Replace($oldGuid, $newGuid)
$page.BeginEdit()
$page.__Renderings = $newRenderings
[void]$page.EndEdit()
}
I have a doubt regarding the change of datasource template of a sublayout. Now, there are two sublayouts: Sub1 and Sub2 which are having Template1 as their datasource template. Until the time I discovered that i need a different datasource template for Sub1, i had already created many items of sublayouts Sub1 and Sub2.
Template2 will now replace Template1 as datasource template for sublayout Sub1.
Now, i have to change the template of all those items that were created with sublayout as Sub1.
The problem is I have to manually change each item's template via content editor--> Configure-->Change Template technique, which is very cumbersome. Is there any other way to change the template of all those items at once ?
I suggest you to install Sitecore PowerShell Extensions and to change the template using the Sitecore PowerShell Console.
$master = [Sitecore.Configuration.Factory]::GetDatabase("master");
$entryTemplate = $master.Templates["your path to template Sub2"];
cd master:\Content\Home\Sub1FolderItems\;
//path to sub1 folder items
Get-ChildItem -recurse | ForEach-Object { if ($_.TemplateName -eq "Sub1") { $_.ChangeTemplate($entryTemplate) } };
There is another way - if you have Sitecore Rocks installed, you can multi-select all the items, right click and select Change Template - no code, and pretty quick unless your content items are in many different places.
As #SitecoreClimber suggested, the best approach to do this is to install Sitecore PowerShell Extensions and fix this with PowerShell. If you don't have admin access or you are not allowed to install PowerShell extensions to your machine, you can use the following .NET code to achieve what you want. Just replace the values of ID variables with the IDs of your templates and sublayouts:
// replace with the first template's ID
ID template1ID = new ID("{A0F73C76-DD4D-4037-90D4-48B616397F5D}");
// replace with the second template's ID
ID template2ID = new ID("{43A1EBB0-CABB-4682-9F5B-7765D7FB0E29}");
// replace with your sublayout's ID
ID sublayout2ID = new ID("{1C6094FA-4539-48E4-A24A-104787641A88}");
Database masterDatabase = Factory.GetDatabase("master");
TemplateItem template2Item = masterDatabase.GetTemplate(template2ID);
// Set to your RootItem
Item rootItem = masterDatabase.GetItem("{756B23C8-1C0F-41AC-9273-B18FDA047925}");
using (new SecurityDisabler())
{
foreach (Item child in rootItem.Axes.GetDescendants())
{
RenderingReference[] renderings = child.Visualization.GetRenderings(Sitecore.Context.Device, true);
IEnumerable<RenderingReference> sublayout2Renderings =
renderings.Where(x => x.RenderingID == sublayout2ID);
foreach (RenderingReference rendering in sublayout2Renderings)
{
if (!string.IsNullOrEmpty(rendering.Settings.DataSource))
{
Item datasourceItem = masterDatabase.GetItem(rendering.Settings.DataSource);
if (datasourceItem != null)
{
if (datasourceItem.TemplateID == template1ID)
{
datasourceItem.ChangeTemplate(template2Item);
}
}
}
}
}
}
I have a joomla template that has two styles. The name of the template is default, and the styles are cats and arts. is there a way to return the name of the current style in use.
the code below only return the name of the template
$template = $app->getTemplate();
if I do an echo $template; I get default. But what I would like to get, is whether I am using the style cats or the style arts
Thank you
The template object doesn't contain the name of the a templates style variations (as it's only really used for human administrators as a mnemonic).
The only way to tell which "style" is being used is to look at the id value of the template… this value will correspond to the one you see in the ID column of the "Template Manager - Styles" view.
// Get the Joomla Application
$app = JFactory::getApplication();
// Get the template
$template = $app->getTemplate(true);
// Echo the ID
echo $template->id;
If you really need the "name" I think you're probably making a design mistake, having said that you could try loading the style model for the $template->id and retrieving it that way. e.g. something like this (warning typed directly into SO, NOT TESTED!)
// Initialise some vars
$name = 'Style';
$prefix = 'TemplatesModel';
$config = array();
// Get the model
$templateStyleModel = JModelLegacy::getInstance($name, $prefix, $config);
// Load the specific style instance.
$templateStyleModel->load($template->id);
// Echo out the style name
echo $templateStyleModel->title;
$params = $app->getTemplate(true)->params;
Use $params->get() to get the particular style's params.
The solution look are looking for is:
$app = Factory::getApplication();
$template = $app->getTemplate(true);
$styleModel = new Joomla\Component\Templates\Administrator\Model\StyleModel();
$style = $styleModel->getItem($template->id);
$style->alias = Joomla\CMS\Filter\OutputFilter::stringURLSafe($style->title);
I need to add a field in basic template. Can anyone help me how can i add another field in include/SugarObjects/templates/basic/vardefs.php in upgrade safe manner.
In VardefManager's function addTemplate not like general standards of Sugar it is not requiring the custom paths
include/SugarObjects/VardefManager.php near line 107 SugarCE6.5.5:
if(empty($templates[$template])){
$path = 'include/SugarObjects/templates/' . $template . '/vardefs.php';
if(file_exists($path)){
require($path);
$templates[$template] = $vardefs;
}else{
$path = 'include/SugarObjects/implements/' . $template . '/vardefs.php';
if(file_exists($path)){
require($path);
$templates[$template] = $vardefs;
}
}
}
Really waiting for awesome responses.
Create a file at the path custom/include/SugarObjects/VardefManager.php with the name VardefManager.php and in that file include your mail file it is include/SugarObjects/VardefManager.php.
Here you will create a class with same and and create a function with the name
static function addTemplate
with same the arguments pass in the main file. and override the method here with your custom code (as you want to add some lines of code in that).
This will be upgrade safe and will be workable to you.
Looking for a quick and easy to query my entire sitecore database (master, web, or pub) and determine where the template for an item no longer exists.
I am trying to serialize my entire tree and I am finding that there are alot of items who's templates have been removed and would like to get a list of them without too much of a headache.
When viewing these items it says template: template no longer exists, here is the code that renders this
private static void RenderQuickInfoTemplate(HtmlTextWriter output, Sitecore.Data.Items.Item item)
{
Sitecore.Data.Items.Item item2;
Sitecore.Diagnostics.Assert.ArgumentNotNull(output, "output");
Sitecore.Diagnostics.Assert.ArgumentNotNull(item, "item");
output.Write("<tr><td>");
output.Write(Translate.Text("Template:"));
output.Write("</td><td>");
using (new SecurityDisabler())
{
item2 = item.Database.GetItem(item.TemplateID);
}
bool flag = (item2 != null) && (CommandManager.QueryState("shell:edittemplate", item) == CommandState.Enabled);
if (flag)
{
output.Write("<a href=\"#\" onclick=\"javascript:scForm.postRequest('','','','shell:edittemplate');return false\">");
}
if (item2 != null)
{
output.Write(item2.Paths.Path);
}
else
{
output.Write(Translate.Text("[template no longer exists]"));
}
Thanks
i think items which base on deleted templates don't inherit from (standard) base template anymore. in quickinfo you should see that their template-ID is something like {000-0000-0000...}
you could try find all the items based on this id.
Two options that come to mind:
Check the Broken Links report
You can right-click on the left 'rail' in the content editor and choose "Broken Links" to show all items that have broken links.
Using the popular powershell module, try
Get-ChildItem -Path "master:\sitecore" -Recurse | ForEach-Object {if (!$_.Template){ write-host $_.ItemPath }}
For me that returns a whole lot of items that I can't open in the content editor.
In case it's just a few items and you want to do everything manually, you can use the dbbrowser:
<yoursiteurl>/sitecore/admin/dbbrowser.aspx.
In case you want to delete these items by script (when there are too many)
$myItemArray = New-Object System.Collections.ArrayList
Get-ChildItem -Path "master:\sitecore\content" -Recurse | ForEach-Object {if (!$_.Template){
$myItemArray.Add($_)
}}
#Show list of Items with invalid template
$myItemArray | Format-Table -Auto -Property Templateid, ItemPath
#Show count of affected items
$myItemArray.Count
$myItemArray #| Remove-Item -recurse
To actually delete the items, remove the '#' in the final line at your own risk. The script takes quite some time to run, and you might need to change the path in case you have broken items outside of content.