Link to an anchor on another episerver page
Is there an elegant way of linking to anchors in some other page in EpiServer that will keep the links relevant - even after the anchor names change? I am 95% sure there is no standard way of doing this, so thoughts on custom implementations are welcome.
There are existing plugins, but ...
I found this plugin to EpiServer that will basically scrape all the anchors from the page you are interested in, and present them in a drop-down in the TinyMCE wysiwyg editor. But as the anchors have no unique attributes that makes it possible to follow them through changes, these anchor links will rot in time, as changing <a name="Meeting"></a>
to <a name="Appointment"></a>
will make previously created links invalid.
Thoughts on how this could work
I am not super-familiar with how to easily work with ContentType
s in EpiServer, but I would assume it should be possible to create some kind of property, HtmlAnchors
, that would be a collection of strings that could be employed on a page. These would be regarded as constants in practice, and I am quite certain that there is a way in EpiServer of checking if a page property is in use, so if one of these strings ( HtmlAnchor
) are referenced on some other page, it would be impossible to delete it without removing the references. That would make anchor links always be consistent and referable.
Possible workflow: An editor opens the page property view and presses the +
sign on the "HtmlAnchors" property. Adds the string "detailed-overview". A front-ender working with code would then add something like that to the page template: <h4 name=@Model.Anchors("detailed-overview")>Overview</h4>
, and in referring pages use the (as of yet non-existing) url helper @Url.PageLinkWithAnchor(Model.PageLink, "detailed-overview")
to create a link to that anchor.
If using a wysiwyg editor then it could use IAnchorPage#Anchors()
to list the existing anchors and IAnchorPage#AddAnchor()
to add an anchor.
Of course, I see how what I sketched out above seems to rest on a shaky foundation, as it uses simple strings ... which might not really add much else than overhead.
链接地址: http://www.djcxy.com/p/68880.html