<![CDATA[ How can I get the parsed content from a document in my snippet? - My Forums]]> https://forums.modx.com/thread/?thread=34771 <![CDATA[Re: How can I get the parsed content from a document in my snippet?]]> https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-550327
How parse string content modx REVO?

parseDocumentSource - is function on modx EVO

I have plugin, it compares the fields and if changed overwrites.
case 'OnBeforeDocFormSave':
/**code**/
if ($mode == 'upd'){
    $oldRes = $modx->getObject('modResource', $data['id']);
    $oldRes = $oldRes->toArray();
   foreach ($fields as $field) {
       if($oldRes[$field] != $data[$field] ){
             /**code**/
             if($field == 'content'){
                 //$outoputContent = $modx->parseDocumentSource($data['content']);
                 $modx->log(xPDO::LOG_LEVEL_ERROR, print_r($data,true));
              }
             /**code**/
       }
}

I need parse resource content and record other table. It's possible ?]]>
kossin Apr 28, 2017, 12:45 PM https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-550327
<![CDATA[Re: How can I get the parsed content from a document in my snippet?]]> https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190483 Quote from: Compeek at Mar 05, 2010, 11:00 PM

Hmm. Well, thanks much for your help, but I think I’m just going to stick with what I have then. On a Revolution site, like you said, this would be much easier, but right now I have code that makes the URLs for me, and Swift Mailer handles placeholders anyway (which I especially need for sending the same email with slight variations to different users).

Thanks. laugh You’re always one of the first people to help me on here, and I really appreciate it.

Thanks for the kind words.

If it ain’t broke . . . wink]]>
BobRay Mar 05, 2010, 10:07 PM https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190483
<![CDATA[Re: How can I get the parsed content from a document in my snippet?]]> https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190482
Thanks. laugh You’re always one of the first people to help me on here, and I really appreciate it.]]>
Compeek Mar 05, 2010, 05:00 PM https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190482
<![CDATA[Re: How can I get the parsed content from a document in my snippet?]]> https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190481 http://wiki.modxcms.com/index.php/API:Template_Service_Events#OnWebPagePrerender. It could check to see if a certain placeholder was set and, if so, email the page and send the user to another document without rendering the page.]]> BobRay Mar 05, 2010, 12:33 AM https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190481 <![CDATA[Re: How can I get the parsed content from a document in my snippet?]]> https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190480
As I’ve been thinking about this, I think it’d work just fine if I got the entire parsed document source (using it’s template and all, not just getting parsed [*content*]) since the email needs a full HTML document to be proper. For the plain text part, I could still just get the tv content and replace the URL tags myself.

Is there any easy way that you know of to get the source of an entire parsed page? I would think that’d be simpler than trying to parse just the content, at least.]]>
Compeek Mar 04, 2010, 11:18 PM https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190480
<![CDATA[Re: How can I get the parsed content from a document in my snippet?]]> https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190479 Quote from: Compeek at Mar 05, 2010, 04:47 AM

I forgot to specify that this is with Evolution, and I believe parseDocumentSource() is only for Revolution, right?

Anyways, as it turns out, I need to do my own placeholder replacing anyway, but the one thing that remains for me to need parsed content is that I don’t want to hardcode the URL to the page that a link in the email needs to point to. I’d like to use the standard [~187~] kind of thing in the document, and I need a way to replace that with the alias. Is that easily doable without parsing the whole page?

No, that’s Evo code. The whole thing would be *much* easier in Revo.

$obj = $modx->getObject('modResource' array('id'=>$docID) ); 
return $obj->process();


The link tag will be replaced by a URL if the document is rendered, but if you’re getting the raw content, you could easily grab the ID from the tag, which you could then use to generate the URL with $modx->makeURL(). There’s no easier way that I know of.


]]>
BobRay Mar 04, 2010, 11:00 PM https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190479
<![CDATA[Re: How can I get the parsed content from a document in my snippet?]]> https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190478
Anyways, as it turns out, I need to do my own placeholder replacing anyway, but the one thing that remains for me to need parsed content is that I don’t want to hardcode the URL to the page that a link in the email needs to point to. I’d like to use the standard [~187~] kind of thing in the document, and I need a way to replace that with the alias. Is that easily doable without parsing the whole page?]]>
Compeek Mar 04, 2010, 10:47 PM https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190478
<![CDATA[Re: How can I get the parsed content from a document in my snippet?]]> https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190477
There’s probably a much easier way, but I think you could use a TV with an @DOCUMENT binding. That should get you the unparsed content field of the document. Then pass that TV to a snippet that calls $modx->parseDocumentSource() to get the parsed result.

To email Document 12, set the DocTv template variable to: @DOCUMENT 12

Then, get the parsed content of document 12:

[!GetParsedContent? &content=`[DocTV]' !]


?<
//GetParsedContent snippet

$output = $modx->parseDocumentSource($content);

// do something with the parsed results here

?>


I’m not sure this would process TV tags in the content correctly but it should handle everything else (if it works at all).

TBH, if all you have to parse are placeholders, it would be much more efficient just to replace them yourself in a custom snippet. You could pass the document’s unparsed content to the snippet using an @DOCUMENT TV as above or with the GetField snippet, or, better, you could just pass the document’s ID to the snippet and have the snippet get the document directly with:
$doc = $modx->getDocument(12, 'content', 1);





]]>
BobRay Mar 04, 2010, 10:39 PM https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190477
<![CDATA[How can I get the parsed content from a document in my snippet?]]> https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190476
In the process of subscribing a new user, I need to send a few emails for confirmation, etc, so I’m using the excellent Swift Mailer library (http://swiftmailer.org/).

To make it easy for the church staff to edit the text of these emails, I’m creating a document (unpublished) for each one, all organized into a subscriptions folder in the site tree.

My question is, how can I get the parsed content of one of these documents in my snippet code so that I can pass it along to Swift Mailer to send the email? I will be setting some placeholders, so that’s the main reason I need to parse the content. Each email has the HTML message in the content field, but I also have a template variable that contains the plaintext version of the message, so it’d be great if I could get that parsed as well.

If that’s not doable, then I could probably write my own code to replace the placeholders with the correct data, but it just makes more sense to use the built-in functionality of MODx to do so.

Thanks!]]>
Compeek Mar 04, 2010, 09:40 PM https://forums.modx.com/thread/34771/how-can-i-get-the-parsed-content-from-a-document-in-my-snippet#dis-post-190476