package blog import ( "gobeyhan/database/models" "fmt" ) templ List(posts []models.Post) { @Layout("Blog Posts") {

Blog Posts

Add Post
for _, post := range posts { }
ID Title Categories Status Created Actions
{ fmt.Sprintf("%d", post.ID) }
{ post.Title }
if len(post.Categories) > 0 { for i, cat := range post.Categories { if i > 0 { , } { cat.Title } } } else { - } if post.IsActive { Active } else { Inactive } if post.IsFront { Front } { post.CreatedAt.Format("2006-01-02") } Edit
} } templ Create(categories []models.Category, tags []models.Tag, errors map[string]string) { @Layout("Create Blog Post") {

Create New Post

if errors["title"] != "" {

{ errors["title"] }

}

Leave blank to generate automatically from title.

if errors["content"] != "" {

{ errors["content"] }

}
if len(categories) > 0 { for _, cat := range categories { } } else {

No active categories found. Add one first.

}
if len(tags) > 0 { for _, tag := range tags { } } else {

No active tags found. Add one first.

}
Cancel
} } templ Edit(post *models.Post, categories []models.Category, tags []models.Tag, errors map[string]string) { @Layout("Edit Blog Post") {

Edit Post: { post.Title }

if errors["title"] != "" {

{ errors["title"] }

}

Leave blank to keep existing or regenerate from title.

@templ.Raw(post.Content)
if errors["content"] != "" {

{ errors["content"] }

}
if post.Image != "" {

Current Preview:

}
for _, cat := range categories { }
for _, tag := range tags { }
Cancel
} } func isCategorySelected(categories []*models.Category, id uint64) bool { for _, cat := range categories { if cat.ID == id { return true } } return false } func isTagSelected(tags []*models.Tag, id uint64) bool { for _, tag := range tags { if tag.ID == id { return true } } return false }