Using Umbraco v6.1.6 I've written a MVC Partial View which is in the Views/MacroPartials folder I created the cshtml file via the Partial View Macro Files option and its visible there. I created a Macro for it as I need it available in the WYSIWYG Content editor. Its displays a google map and applies some markers.
When I apply it to a template it previews fine and all works. However when I reference the Macro directly in the Content editor and not via a Template it doesn't work and renders no markup. I've checked the Use In Editor and Render content in editor checkboxes in the Macro.
Am I doing something wrong with the setup? Is there a better way?
Unfortunately the rendering of Macros within the WYSIWYG editor (TinyMCE) isn't great.
There are a few things to keep in mind with it, e.g. what type of HTML is being rendered - anything beyond basic formatting may have adverse side-effects, like <script>, <embed> or <iframe> tags.
It all depends on what you are wanting to achieve (for the content editor).
It is tricky to strike a balance between a functional macro and having that render nicely within the rich-text editor (TinyMCE).
One approach that I have taken is to render different markup for the rich-text editor.
When a macro is inserted into the rich-text it makes a call to a core page called macroResultWrapper.aspx - this is responsible for rendering the macro for the rich-text editor. To do this a querystring parameter called umb_macroAlias is passed to it with the alias name of the macro.
Then you can take advantage of the umb_macroAlias querystring parameter within your own macro. So instead of rendering the full Google Map JavaScript version you could render a light-weight version: e.g. a static image.
@if(!string.IsNullOrEmpty(Request.QueryString["umb_macroAlias"]))
{
// render the rich-text editor friendly version: e.g. static image map
}
else
{
// render the original Google Map
}
Macro renders correctly in template but not in WYSIWYG editor
Hello
Using Umbraco v6.1.6 I've written a MVC Partial View which is in the Views/MacroPartials folder I created the cshtml file via the Partial View Macro Files option and its visible there. I created a Macro for it as I need it available in the WYSIWYG Content editor. Its displays a google map and applies some markers.
When I apply it to a template it previews fine and all works. However when I reference the Macro directly in the Content editor and not via a Template it doesn't work and renders no markup. I've checked the Use In Editor and Render content in editor checkboxes in the Macro.
Am I doing something wrong with the setup? Is there a better way?
Thanks for looking
Hi,
Unfortunately the rendering of Macros within the WYSIWYG editor (TinyMCE) isn't great.
There are a few things to keep in mind with it, e.g. what type of HTML is being rendered - anything beyond basic formatting may have adverse side-effects, like
<script>
,<embed>
or<iframe>
tags.It all depends on what you are wanting to achieve (for the content editor).
Cheers,
- Lee
Hi Lee
Thanks for taking the time to reply.
Is there an alternative approach to take? I have a cshtml file which is rendering a google map and I want it to be available in various content pages.
Thanks
It is tricky to strike a balance between a functional macro and having that render nicely within the rich-text editor (TinyMCE).
One approach that I have taken is to render different markup for the rich-text editor.
When a macro is inserted into the rich-text it makes a call to a core page called
macroResultWrapper.aspx
- this is responsible for rendering the macro for the rich-text editor. To do this a querystring parameter calledumb_macroAlias
is passed to it with the alias name of the macro.Then you can take advantage of the
umb_macroAlias
querystring parameter within your own macro. So instead of rendering the full Google Map JavaScript version you could render a light-weight version: e.g. a static image.(Take a look at Google Maps Image APIs documentation)
Quick example of the logic:
Good luck!
Cheers,
- Lee
is working on a reply...