Content Editor Web Part Not Rendering Due to Link
-
21-12-2020 - |
Question
I have a problem with a CEWP not rendering because of the link entered. It is a custom WP, but what was customized is just the CSS, so I'm pretty sure that the CSS isn't causing the issue. I have the WP in a particular site collection. For some reason, absolute links cause the WP to not render properly, it just shows the text of the WP file, so I'm trying to use the relative URL instead. In general, relative links work, but the link I need (which points to a page in a subsite) causes the WP to not render properly like it does with absolute URLs.
The current URL where the CEWP is placed is: /sites/Blah/Pages/Home.aspx
While the URL I'm trying to point to is: /sites/Blah/Subsite/default.aspx
The link I'm trying to add in the CEWP is: ../Subsite/default.aspx
I need ../ since it has to go up a level, then append the link or else the CEWP link resolves to /sites/Blah/Pages/Subsite/default.aspx, which doesn't exist and leads to a Page Not Found.
I've read multiple posts talking about this relative URL 'problem', but I haven't found one that had a solution involving linking to a subsite and not just some asset file. I'm pretty sure ../ is causing the problem, but I don't understand why.
Solution
I think you can not use relative links with .. (parentside) references
It is probably programmed that way because a WebPart can be saved as Template
and placed on another site that link will most likely break.
Not to confuse users, MS just disabled all relevative links
If you want dynamic loading of a script then do that with JavaScript inside WebPart code
Pseudocode:
<SCRIPT>
var myscr=document.createElement('SCRIPT');
myscr.src="../myrellink/myscript.js";
myscr.onload=function(){
console.log('The Blue pill or the Red pill?');
}
document.head.appendChild( myscr );
</SCRIPT>
OTHER TIPS
Make sure your CSS is wrapped in a <style></style>
tag