logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
ray22901031  
#1 Posted : Monday, June 17, 2024 2:08:25 AM(UTC)
ray22901031

Rank: Advanced Member

Groups: Authorized User, Developers
Joined: 2/17/2019(UTC)
Posts: 907

Thanks: 3 times
Was thanked: 15 time(s) in 15 post(s)
Is there a way to insert an HTML snippets into an csHTML file?

Please allow me to explain. I'm constantly manipulating the _MetaTags.cshtml file. Please review what my current file looks like below. As you can see, I have manipulated the language tag, added og types, and am now in the process of adding Twitter tags. It would be more efficient if this information was stored in an html Snippet that I can just call.

If there is no way to do this today? If not, I highly recommend in the future version, that there be a configuration in the back-end where we can manipulate this file without having to directly insert code

I look forward to your feedback. - thanks
-Ray

---- start

<html class="no-js" lang="en-US">
<meta http-equiv = "content-language" content = "en">

@if (!string.IsNullOrEmpty(description)) {
<meta name="description" content="@description">
}
@if (!string.IsNullOrEmpty(keywords)) {
<meta name="keywords" content="@keywords">
}
@if (!string.IsNullOrEmpty(objectUrl) && (!objectUrl.Contains("Default"))) {
<link rel="canonical" href="@objectUrl" />
}
@if (objectUrl.EndsWith("/Default")) {
<link rel="canonical" href="@webUrl" />
}

<meta property="og:type" content="website">
<meta property="og:title" content="MyRadioMall.com | Buy Motorola Radios for less.">
<meta property="og:description" content="MyRadioMall.com provides nationwide sales of Motorola Radios.">
<meta property="og:url" content="https://www.myradiomall.com/">
<meta property="og:site_name" content="MyRadioMall.com">
<meta property="og:image" content="https://www.myradiomall.com/Themes/MRM-Default-Wide-2023/content/images/logo.webp">

---- end

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

ray22901031  
#2 Posted : Wednesday, June 19, 2024 10:53:05 PM(UTC)
ray22901031

Rank: Advanced Member

Groups: Authorized User, Developers
Joined: 2/17/2019(UTC)
Posts: 907

Thanks: 3 times
Was thanked: 15 time(s) in 15 post(s)
I'm going to take a guess and say this cannot be done. In a future version, it would be nice to have a text box in the backend that lets you insert stuff directly into this tag view instead of manually entering it.

I'll take it one step further: the ability to insert HTML snippets into view files would help keep everything under control, especially when the site grows large.

Thanks

Edited by user Wednesday, June 19, 2024 10:54:36 PM(UTC)  | Reason: Not specified

nadeem  
#3 Posted : Friday, June 21, 2024 10:54:06 AM(UTC)
nadeem

Rank: Advanced Member

Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System
Joined: 10/11/2018(UTC)
Posts: 110

Thanks: 19 times
Was thanked: 18 time(s) in 18 post(s)
Hi Ray,

Yes, this isn't currently supported out of the box to insert HTML Snippet to view file without customization.

You can achieve this by making a small customization. That is, you can load the HTML Snippet contents and render in existing _MetaTags.cshtml file.
To do so, replace the following code

Code:

@{
    string description = ViewBag.MetaDescription ?? string.Empty;
    string keywords = ViewBag.MetaKeywords ?? string.Empty;
    string objectUrl = ViewBag.ObjectUrl ?? string.Empty;
}


with

Code:

@using CommerceBuilder.CMS;
@{
    string description = ViewBag.MetaDescription ?? string.Empty;
    string keywords = ViewBag.MetaKeywords ?? string.Empty;
    string objectUrl = ViewBag.ObjectUrl ?? string.Empty;
    int metaTagsHtmlSnippetId = 1; // replace with the actual id of the HTML snippet you created in Admin
    var metaTagsHtmlSnippet = AbleContext.Resolve<IHtmlContentRepository>().Load(metaTagsHtmlSnippetId);
}
@if (metaTagsHtmlSnippet != null && !string.IsNullOrEmpty(metaTagsHtmlSnippet.Html))
{
    @Html.Raw(metaTagsHtmlSnippet.Html)
}


Hope this helps!
ray22901031  
#4 Posted : Friday, June 21, 2024 11:02:42 AM(UTC)
ray22901031

Rank: Advanced Member

Groups: Authorized User, Developers
Joined: 2/17/2019(UTC)
Posts: 907

Thanks: 3 times
Was thanked: 15 time(s) in 15 post(s)
Thank you so much for taking the time to check into the code. It will be a time saver for me and, I believe, many other people. I have already created an HTML snippet called "_MetaTags.cshtml."

I'm very happy that the HTML snippet name will accept underscores and dots; this way, I will actually name them the file name that they are going to be inserted in.

Once again, many thanks for your exceptional work. - This makes life so much easier.

thanks 1 user thanked ray22901031 for this useful post.
nadeem on 6/21/2024(UTC)
nadeem  
#5 Posted : Friday, June 21, 2024 11:07:39 AM(UTC)
nadeem

Rank: Advanced Member

Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System
Joined: 10/11/2018(UTC)
Posts: 110

Thanks: 19 times
Was thanked: 18 time(s) in 18 post(s)
Thank you!!
Happy to help :)
ray22901031  
#6 Posted : Monday, June 24, 2024 12:26:03 PM(UTC)
ray22901031

Rank: Advanced Member

Groups: Authorized User, Developers
Joined: 2/17/2019(UTC)
Posts: 907

Thanks: 3 times
Was thanked: 15 time(s) in 15 post(s)
Hi nadeem,

Again, thank you for your effort in getting this done. You have no idea how our lives have now been simplified because of this. We have probably manipulated in total over 15 view files, and to have to maintain or update code is the biggest pain in the butt.

We are slowly simplifying the view files by implementing the HTML Snippets insert. Please see the Screenshot provided. Right now, we have already converted two of them.

I just want to show you what a time-saving feature this is. Hopefully, this can benefit other developers. We have created the following name syntax to make our lives easier. This is a three-step naming convention.

All HTML Snippets that deal with view files start with "ViewFiles" + space + The name of the view file itself, whether it's partial or not + its primary purpose for modification.

We had to add Twitter cards to the existing code, and what a simple process it was to go into the appropriate HTML Snippets, make the change, and save without having to log into the main server, download, edit, and upload.

Thank you for the early Christmas gift

HTML Snippets.jpg (158kb) downloaded 8 time(s).
thanks 1 user thanked ray22901031 for this useful post.
nadeem on 6/25/2024(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.