donatas Posted February 1 Share Posted February 1 I want to keep the full absolute local URLs inside my TinyMCE field (edit: I'm using it to send email content), but after saving they are all overwritten with relative paths to the existing pages (edit: and relative links don't work in emails) Example: https://domain.com/my-link/ becomes /my-link only. And I need the full https://domain... version. I think I had seen such option some time ago, but maybe I'm mistaken? "Link abstraction" doesn't seem to fix this. I've tried many options in the field configuration, but no luck. Any advice? For now I am adding the domain back while rendering output with a hook for this field, but I'd rather not. Link to comment Share on other sites More sharing options...
Robin S Posted February 1 Share Posted February 1 Using full absolute URLs for internal website links is liable to cause trouble down the line. For example, if the website domain changes you have to update every internal link. Instead you could add a <base> element to your _main.php. 1 Link to comment Share on other sites More sharing options...
donatas Posted February 2 Author Share Posted February 2 I know, I wouldn't want this for a regular page. But I'm using this field for email content that is being sent and links have to be full absolute URLs to work - that's the issue. The field has to be user-friendly, I can't use raw html. It's edited quite often. I would even like to use the page selector in the pwlink plugin, but that the links should remain absolute. Link to comment Share on other sites More sharing options...
Robin S Posted February 2 Share Posted February 2 1 hour ago, donatas said: But I'm using this field for email content that is being sent and links have to be full absolute URLs to work - that's the issue. Right, makes sense. You could change to a CKEditor field as this keeps full absolute URLs if you paste them in. But I actually think this is a good use case for a hook like you are already using, or a custom textformatter module. That way you can use all the normal features of the pwlink plugin and the string replacement is dead simple. Link to comment Share on other sites More sharing options...
MarkE Posted February 2 Share Posted February 2 Thanks for raising this issue @donatasand @Robin S. I was just about to consider changing a CKEditor field to TinyMCE, where the field is used in exactly this way, except that the url is inserted via a Hanna code. Link to comment Share on other sites More sharing options...
bernhard Posted February 2 Share Posted February 2 Link to comment Share on other sites More sharing options...
monollonom Posted February 3 Share Posted February 3 I more or less do the same as @bernhard in the PageMjmlToHtml module Link to comment Share on other sites More sharing options...
bernhard Posted February 3 Share Posted February 3 Using RockFrontend you could also do this, for example inside a saveReady hook: <?php use Wa72\HtmlPageDom\HtmlPageCrawler; $dom = rockfrontend()->dom($page->body); $dom ->filter("a") ->each(function (HtmlPageCrawler $node) { $href = $node->getAttribute("href"); if (!$href) return; if (strpos($href, "http://") === 0) return; if (strpos($href, "https://") === 0) return; $https = rtrim($this->wire->pages->get(1)->httpUrl(true),"/"); $node->setAttribute("href", $https.$href); }); $page->set('body', $dom->html()); I've added docs for it on the dev branch: https://github.com/baumrock/RockFrontend/tree/dev/docs/dom Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now