HTML Preview shows wrong draft page

#1

I have a Draft todo list that I want to preview in HTML and I’ve built an action that consists of the URL and HTML preview.

The problem is the HTML preview shows the exiting draft page not the landing draft page. I’ve tried a number of different ways of slowing the preview to try and make sure the todo list draft was fully loaded, including separating the HTML preview as an Action.

Any ideas would be appreciated.

0 Likes

#2

can you share your action / code here (its possible to share them unlisted in the directory)?

a quick guess would be that the “draft” object is still the draft which was displayed when you started the action.

0 Likes

#3

Hi @FlohGro,

The action is very simple, it consists of only 2 Steps:

  1. the URL to the draft uuid (drafts5://open?uuid=…) and
  2. the built-in HTML Preview.

It does seem that, even though the URL step is triggered and the draft object is displayed, the preview is from the draft that was displayed when the action was triggered.

0 Likes

#4

Yes - that is actually as designed. When you run the action, you are running it against the draft you first had available - aka the current draft. All steps are run against that draft. That’s a particularly important concept should you ever choose to batch process drafts.

If you want to run stuff against a different draft then you have to come at it slightly differently.

You could change your action to pull the content of the to do draft rather than the current draft and preview that - you wouldn’t even have to change drafts.

Alternately, if you want to change drafts, you could split your action steps into two actions, and then add a second step at the end of the action of the first one, to queue the second action. Take a look at the queueAction() function available to use in Script steps. I believe this should work, but I haven’t tried it when switching drafts.

Hope that helps.

0 Likes

#5

try this:

var todoDraft = Draft.find("YOUR_TODO_DRAFTS_UUID");
editor.load(todoDraft);
draft = todoDraft;

app.queueAction(Action.find("htmlPreview",draft);

like @sylumer said, you need to have a seperate action for the html preview (named htmlPreview in my example).
then it will work.

0 Likes

#6

Just to complement @FlohGro’s example, here’s the other way of doing it I suggested.

This action has two steps. The first is the script step that stores the content of the, for want of a better term, ‘special’ draft, in a tag associated with the current draft. For your circumstances this would be your to do draft.

//Change the UUID in the find parameter below to be your own draft
draft.setTemplateTag("SpecialContent", Draft.find("1DA77A51-F1D0-4810-A69C-3A59035B6AB3").content)

Simply substitute in your UUID for the one I used for my test.

Note the tag being created is called “SpecialContent”.

The second step is a standard preview step, but I swapped out the %%[[draft]]%% tag for %%[[SpecialContent]]%% instead.

This doesn’t load the draft into the editor, so if preview rather than edit is preferred then this would be a better option. If you want to load the draft too, then the previous solution would be appropriate.

Whilst you could of course add a load step as a third step in this action, thus keeping it all in one action, if you have tailored styling for the preview and wish to re-use it across multiple similar actions, then the previous solution where it splits the actions would be more efficient overall as you could retain a single style source.

There are other ways to do that, but it would be the easiest to maintain.

Hope that helps.

0 Likes

#7

Thank you @sylumer and @FloGro for your great suggestions. I’ve tried both and have used @sylumer’s action, as it’s the one I can understand best. I now have a good productive todo list.

Cheers,

2 Likes