I'm wondering if there's a way to embed / include / import a cshtml file into another cshtml file, where both files are only being edited within the Umbraco v7 backend.
A friend has an old v7 site where all the source code has been lost. They're spec'ing out a whole new site, but in the mean time has asked me to add content from a JSON API to content that's already on a few pages of the existing v7 site.
We still have access to the backend and I've managed to do what I want using an @functions block that is copied on to each page requiring the new content. The new content gets added to a List along with the present content and then each page renders it slightly differently. I did it this way, so basically I'm messing with the Model only not Model and View. The rendering "code" remains exactly the same.
It works OK, but the code is duplicated so is a pain.
Is there anyway to have my @functions block in a separate file and then include it in each of the partials / pages that require it as though it was copied-n-pasted in?
Just as a test I tried ChatGPT with the same question and heres a link to the conversation. It sounds hopeful, but I think it may be getting Umbraco versions mixed up as I still haven't quite got it working.
Include file within Razor cshtml file
Hi,
I'm wondering if there's a way to embed / include / import a cshtml file into another cshtml file, where both files are only being edited within the Umbraco v7 backend.
A friend has an old v7 site where all the source code has been lost. They're spec'ing out a whole new site, but in the mean time has asked me to add content from a JSON API to content that's already on a few pages of the existing v7 site.
We still have access to the backend and I've managed to do what I want using an @functions block that is copied on to each page requiring the new content. The new content gets added to a List along with the present content and then each page renders it slightly differently. I did it this way, so basically I'm messing with the Model only not Model and View. The rendering "code" remains exactly the same.
It works OK, but the code is duplicated so is a pain.
Is there anyway to have my @functions block in a separate file and then include it in each of the partials / pages that require it as though it was copied-n-pasted in?
Hi David,
I don't know if this would be possible in Umbraco, but worth a try
https://www.c-sharpcorner.com/UploadFile/56fb14/reusable-methods-in-razor-view-using-inline-helper-method/
Hi Huw,
That might well be the best way. It does involve adding a file into the App_Code directory via ftp (or something).
Was trying to find a way to do it purely by the backend?
Thanks Dave
Just as a test I tried ChatGPT with the same question and heres a link to the conversation. It sounds hopeful, but I think it may be getting Umbraco versions mixed up as I still haven't quite got it working.
is working on a reply...