Orchard.Templates

Topics: Administration, Core, Customizing Orchard, General, Writing modules, Writing themes
May 9, 2014 at 7:17 PM
How can i use Orchard.Templates? Why there is no documentation for it. It cannot be useful without documentation?
How must i use it for sending email? What is main usage of new Templates feature in Orchard 1.8?
Also UI for selecting tokens is very dirty with very bad notation that is hard to understand.
We must remember that Orchard is a general purpose CMS. Most users of a CMS are not programmer.
Developer
May 10, 2014 at 10:47 PM
It's a module for creating templates (like Razor templates) from the admin UI. Such templates are also picked up by the display engine and thus can be used e.g. to override shape templates (like the one used for e-mails).
May 10, 2014 at 11:29 PM
Can you say an example? How can use it?
May 12, 2014 at 9:00 AM
class--------place
SmtpMessageChannel -------- _shapeDisplay.Display(template),
class ShapeDisplay : IShapeDisplay------((DisplayHelper)display).ShapeExecute(shape).ToString();
class DisplayHelper : DynamicObject------ return _displayManager.Execute(context);
class DefaultDisplayManager : IDisplayManager------- _shapeDisplayEvents.Invoke(sde => sde.Displaying(displayingContext), Logger);
TemplateShapeDisplayEvent : IShapeDisplayEvents ------- public void Displaying(ShapeDisplayingContext context) {
        var processors = BuildShapeProcessors();
        Func<dynamic, IHtmlString> processor;

        if (processors.TryGetValue(context.ShapeMetadata.Type, out processor)) {
            context.ChildContent = processor(context.Shape);
        }
    }
Aug 5, 2014 at 10:58 PM
Why there is no document or sample for usage of this module?
I am searching for a way to use a template content item as an email template in "send email" activity in workflow. Anybody can guide me please?
Developer
Aug 6, 2014 at 8:55 AM
It's a relatively new module, and no one took the time yet to document or blog about it. We'll get to it eventually, but here's what you do in a nutshell:
  1. Create your Template and give it a name, e.g. MyEmailTemplate.
  2. In your "send email" activity, configure the body text to use the following token: {Shape.Execute:MyEmailTemplate}.
The Shape:Execute token will render the specified shape name and use its HTML as the email body.
Coordinator
Aug 6, 2014 at 7:48 PM
And I would add that you can already edit your template in the Activity form, so this technique is not that useful in most cases. What templates can be used for instead, is to override existing email templates, like the Register user message, or the main email wrapper defining the default format.
Aug 6, 2014 at 8:09 PM
Edited Aug 6, 2014 at 8:11 PM
@sfmskywalker, Thank you very very very much for your comment. Is there any way to use tokens in MyEmailTemplate?
@sebastienros, Thank you. Can you say more about how can i override existing email templates by Orchard.Templates? Where is Register user message template or main email wrapper?
Coordinator
Aug 6, 2014 at 8:16 PM
The default templates from Orchard.Users are
  • Template.User.LostPassword
  • Template.User.Moderated
  • Template.User.Validated
  • Template.User.Wrapper
Look at their source code, and create a template with the same name to override it.

You might have to call them Template_User_Validated for instance
Aug 6, 2014 at 8:35 PM
Ooh, Very beautiful feature. Thank you so much @sebastienros. Is there any way to use tokens in these created templates or they must be only HTML mark up?
Always Templates in Orchard.Templates can override all templates of modules and themes if they have correct name?
Excuse me for taking your time.
Aug 6, 2014 at 9:06 PM
I tested it. I am surprised. That is very good and useful module. It seems only limitation is we cannot use tokens of Workflow's ContentItem in templates.
Special thanks to @sebastienros and @sfmskywalker.
Aug 6, 2014 at 9:19 PM
Orchard is my love. We can even use tokens in Templates through shape model.
Aug 31, 2014 at 11:47 AM
I have created template with name "List" and my dashboard is broken now.
How can I fix it? How to delete this template? Is there database table?
Aug 31, 2014 at 12:09 PM
musukvl wrote:
I have created template with name "List" and my dashboard is broken now.
How can I fix it? How to delete this template? Is there database table?
Hello,

Imgur

Find the id and then delete records with that id from all the tables
Orchard_Framework_ContentItemRecords
Orchard_Framework_ContentItemVersionRecord
Common_CommonPartVersionRecord
Common_CommonPartVersionRecord
Common_IdentityPartRecord

After that restart your website.

Let me know.
AL
Aug 31, 2014 at 4:49 PM
Edited Aug 31, 2014 at 5:30 PM
IMHO, Right way is:
  1. Find ContentItemRecord_id with select * from Title_TitlePartRecord
  2. Delete with following url: /Admin/Contents/Remove/{id}
But it is the very funny problem.
In fact you can create List.cshtml in your theme and it will affect all lists in Dashboard.
Why? For the glory of Satan of cause!
Aug 31, 2014 at 5:58 PM
musukvl wrote:
IMHO, Right way is:
  1. Find ContentItemRecord_id with select * from Title_TitlePartRecord
  2. Delete with following url: /Admin/Contents/Remove/{id}
But it is a very funny problem.
In fact you can create List.cshtml in your theme and it will affect all lists in Dashboard.
Why? For the glory of Satan of cause!
Yes that's the right way if u do it from the back-end(Soft Delete). Why not use Shape Tracing n url alternates.
Developer
Aug 31, 2014 at 7:23 PM
http://x2.fjcdn.com/thumbnails/comments/5274475+_3a67ac13ddc03823db3eb4fd0dcc26d0.png

That templates created through Orchard.Templates live on the admin area as well as the frontend is a feature (I don't know whether this was intended or not but I consider it as a useful feature). This, in turn, can enable you to break admin. I don't know what we can do: with the great power of editing templates from the admin comes the great responsibility of breaking everything and then having to dig into the DB to clean up the mess.
Sep 12, 2014 at 11:47 PM
I think Orchard.Templates is very very good feature.
Mar 11, 2015 at 8:26 PM
Sorry to be digging up an old post. From what I gather in this thread, Templates are for e-mail templates.

A couple of questions:

1) Can they be used in other scenarios? For example, rather than create a module to have a shape display some logic (form, summary of data entered on form, or some other message logic)?
2) If so, how would you go about utilizing them? For example, I do not see an ability to select a template on any content types. Like a "Template selector".
3) Are tokens the only way to utilize them?
4) If so, and if they are usable outside of e-mail templates, how would you go about doing that?

Thanks.
Mar 11, 2015 at 8:48 PM
I think I may have answered my questions. I used Orchard.Layouts. I inserted a Snippet>Shape and named it exactly as the Orchard.Template I named (Test_Template) and it displayed on the page using the Test Layout I created.

This is awesome, because using Orchard.Layouts and Orchard.Templates is not something readily discussed anywhere.

If there are any limitations or if you would like to expand on my questions, it is much appreciated.