How do I add space between List items in SwiftUI - swiftui

I am trying to add space between each list item and separate them out (see images for further explanation).
I have tried adding padding, but it only adds to the text, not the items themselves.
What I Have:
What I Want:

#Sweeper is correct. You want to place each view from the List in a Section. That will separate each concert artist and date from each other. Adjust spacing according to however you want it.
List {
Section {}
Section {}
Section {}
}

Related

MVC ModelState Remove keys when deleting item in a list model

In an MVC View when a user deletes an item in a list (e.g. using an Edit Template), an associated action may be used to remove that item from the view model. However, the item may still show in the re-rendered view. Even if the view contains one less item, the wrong item may be have been removed from the displayed items.
Because ModelState is the first choice [before the (view) model] for the display of data in the view, this must also be edited to remove the deleted item.
What is the best way to manage this scenario?
I can remove all entries for a list if I know what the starting name
e.g.
MyItems[0].Id
MyItems[0].Name
MyItems[1].Id
MyItems[1].Name
A static helper can be used as follows
ModelState.Remove_StartsWith("MyItems");
Although this will also remove any items with errors. Since the ModelState keys have a particular form : name[n].name - to remove only the one item matching the model item requires not only finding that item in ModelState but also managing the index numbers of the ModelState keys - probably creating a new ModelState with the updated key list in contiguous order
/// <summary>
/// Remove all entries where a key starts with a given value
/// This will remove list entries
/// </summary>
/// <param name="dic"></param>
/// <param name="startsWith"></param>
static public void Remove_StartsWith(this ModelStateDictionary dic, string startsWith)
{
foreach (string key in dic.Keys.Where(k => k.StartsWith(startsWith)).ToList())
{
dic.Remove(key);
}
}

Sitecore TreelistEx used as a UI for multi-link layouts

I need to present a content editor interface that allows editors to select specific pages in order to generate a link list for website visitors.
It seems treelist/treelistEX is providing the expected interface and I have combined that with a source path to lock the editors to a start destination rather than the entire sitecore tree. Opted for treelist EX as this appears to be the most efficient way as it doesnt render the tree in full each time unless its called upon.
In terms of the output however I'm getting a pipe separated list of GUIDs- is this something I need to iterate through manually using linkmanager or some such to obtain the items title and its sitecore link? Or is there an existing process that manages such a multi-list and breaks it up into its components.
If anyone can provide an example of that code and how to draw out the title and URL that would be great.
Thanks
There is no built-in solution for getting title and url from the items selected in Treelist.
You can treat your Treelist field as a Multilist field (they both store just list of pipe separated IDs in the background) and use GetItems() method:
Sitecore.Data.Fields.MultilistField treelistField = Sitecore.Context.Item.Fields["myTreelistFieldName"];
Item [] selectedItems = treelistField.GetItems();
foreach (Item item in selectedItems)
{
string itemName = item.Name;
string displayName = item.DisplayName; // fallback to Name if not set
string title = item["Title"]; // assuming there is a field called Title
string url = LinkManager.GetItemUrl(item);
}

Sort 'Days' Items in Sitecore according to days of week

Is there any way to sort the following items according to the days of week.
In C# I can do something like this:
string [] initialArray = {"Friday", "Monday", ... } ;
string [] sortedArray = initialArray.OrderBy(s => Enum.Parse(typeof(DayOfWeek), s)).ToArray() ;
But I don't know how can I achieve this kind of functionality with Sitecore.
If what you really care is to display the days sorted on the front-end regardless of how they are organised in the Content Editor then simply sort them in code before you display them, e.g.
using System.Linq;
var openingHours = Sitecore.Context.Item.Children
.OrderBy(s => Enum.Parse(typeof(DayOfWeek), s.DisplayName));
If you want to sort them in the Content Editor then you need to create a custom sorter. Sitecore Climber has provided links, but for this specific example you can use:
using Sitecore.Data.Comparers;
using Sitecore.Data.Items;
public class DayOfWeekComparer : Comparer
{
protected override int DoCompare(Item item1, Item item2)
{
var x = (int)Enum.Parse(typeof(DayOfWeek), item1.DisplayName);
var y = (int)Enum.Parse(typeof(DayOfWeek), item2.DisplayName);
return x.CompareTo(y);
}
}
Then in the core database create an item of item type /sitecore/templates/System/Child Sorting under /sitecore/system/Settings/Subitems Sorting and set the type to your class.
You should set the Subitem Sorting on the Standard values of a template. In this instance it looks like you have a simple Folder template, so you would need to create a more specific template for your Opening Hours folder. Even so, the user can still decide to re-order the items OR change the default sort for that folder. The only guaranteed way to force the output is by sorting before you render, i.e. the first bit of code.
please check next articles:
http://firebreaksice.com/how-to-sort-sitecore-items-in-the-content-editor/
http://sitecore.alexiasoft.nl/2009/08/04/sorting-sitecore-items/
http://sitecoreblog.blogspot.in/2010/11/change-default-subitems-sort-order.html

Add and delete buttons in django jquery dynamic formset

I use https://github.com/elo80ka/django-dynamic-formset to add and delete rows from a formset.
The problem is that the add row and delete row buttons are automatically inserted weird places.
Can I place these buttons manually?
Or are there any other jquery libraries to add and delete rows in a formset dynamically?
I don't think you can place these buttons manually, maybe if you check the rules followed by the plugin to place the buttons: https://github.com/elo80ka/django-dynamic-formset/blob/master/src/jquery.formset.js#L49
As you can see:
//If the forms are laid out in table rows, insert
// the remove button into the last table cell
// If they're laid out as an ordered/unordered list,
// insert an < li > after the last list item
// Otherwise, just insert the remove button as the
// last child element of the form's container
You can specify addCssClass (which is by default 'add-row'), maybe that can help you.

Sitecore 6 - how to store html-formatted text and reference in codebehind

I would like to be able to store reusable html-formatted text in Sitecore and reference in codebehind for inclusion in a custom user control. What is the best practice for doing this? If a user selects option A, for example, I would reference standard text A in my control. Any examples for how to accomplish this are appreciated. Thanks.
You have a couple options:
Store the text in the Standard Values of the same template that defines your option list. That makes it available on the same item, but standard for all items. Use security to lock down the field if you are worried about it being edited. This could also be accomplished with the new "cloning" feature in 6.4, I believe.
Create a structure outside of your Home element for storing this data. Based on the option selected, find an item in your content tree which corresponds to the selected item, and read the text off of it. You would need to find this item either relative to /sitecore/Content, or relative to your website root if multi-site support is a requirement.
No.2 in pseudo-code:
//get the item where we have the text values
Item textBase = Sitecore.Context.Database.SelectSingleItem(textBasePath);
//find the child w/ the same name as the selected option
Item textItem = textBase.Axes.GetChild(selectedOptionValue);
string value = textItem["text"];
I think I would do something like techphoria414's 2. option:
ie you have your normal "page" templates as per usual, but then you have some fields (multilist, treelist fields), where you put the source pointing to your other items contain the different texts.
then you basically just have to get the items from the current item (with some very quick'n'dirty code/pseudocode):
var CurrentItem = Sitecore.Context.Item;
Sitecore.Data.Fields.MultilistField mlf1 = CurrentItem.Fields["myExternalTexts"];
if(mlf1 != null)
{
foreach (Item itm in mlf1.GetItems())
{
lit += Sitecore.Web.UI.WebControls.FieldRenderer.Render(itm, "richtext");
}
}
You ofc shouldn't just add them to a literal and you should you Sitecore built in Field renderes if using Sitecore 6 or above and it's a Rich text field.
I hope that helps.