Created
April 15, 2015 13:08
-
-
Save Dillie-O/dc286ad2c1353b3531cd to your computer and use it in GitHub Desktop.
SiteFinity Retrieve FeeValue Content Block from Shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class FeeValueShortcodeProcessor | |
| { | |
| /// <summary> | |
| /// Expands all FeeValue shortcodes in the specified text | |
| /// </summary> | |
| /// <param name="inputText">The input text.</param> | |
| /// <returns>String with replaced short code values</returns> | |
| public static string Expand(object inputText) | |
| { | |
| if (inputText == null) return string.Empty; | |
| var result = inputText.ToString(); | |
| // use regex to find matches | |
| const string regex = @"\[FeeValue:(?<title>.*?)\]"; | |
| var matches = Regex.Matches(result, regex); | |
| foreach (Match match in matches) | |
| { | |
| // Get Fee Title | |
| var feeTitle = match.Groups["title"].Value; | |
| // Replace shortcode text with retrieved Fee value from shared | |
| // content blocks. Filter by the FeeValues category so that we don't | |
| // get things mixed up with any actual content blocks. | |
| var taxManager = TaxonomyManager.GetManager(); | |
| var catManager = taxManager | |
| .GetTaxonomies<HierarchicalTaxonomy>() | |
| .SingleOrDefault(s => s.Name == "Categories"); | |
| var feeValuesCategory = catManager.Taxa.FirstOrDefault(c => c.Title == "FeeValues"); | |
| var categoryId = feeValuesCategory.Id; | |
| var manager = ContentManager.GetManager(); | |
| var contentItem = manager | |
| .GetContent() | |
| .FirstOrDefault(x => x.GetValue<TrackedList<Guid>>("Category").Contains(categoryId) | |
| && x.Title == feeTitle | |
| && x.Status == ContentLifecycleStatus.Live); | |
| var feeValue = contentItem != null ? contentItem.Content.ToString() : "FEE VALUE NOT FOUND"; | |
| result = result.Replace(match.Value, feeValue); | |
| } | |
| return result; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment