> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/lopiv2/invenicum/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates

> Use and create collection templates from the marketplace

## Overview

Templates provide pre-configured collection structures that you can use as starting points for your inventory. Each template includes custom field definitions, asset types, and organizational patterns optimized for specific use cases.

## Template Marketplace

The template marketplace offers community-created templates for various inventory types:

<CardGroup cols={2}>
  <Card title="Gaming Collections" icon="gamepad">
    Templates for video games, board games, and collectibles
  </Card>

  <Card title="Electronics" icon="microchip">
    Templates for tech inventory and equipment tracking
  </Card>

  <Card title="Books & Media" icon="book">
    Templates for libraries, media collections, and archives
  </Card>

  <Card title="Business Assets" icon="briefcase">
    Templates for office equipment and business inventory
  </Card>
</CardGroup>

### Browsing Templates

Access the marketplace through the Templates section:

<Steps>
  <Step title="Navigate to Market">
    Open the template marketplace from the main navigation. The screen displays available templates with preview cards.
  </Step>

  <Step title="Filter by Tags">
    Use tag filters to narrow down templates:

    ```dart theme={null}
    // From asset_templates_market_screen.dart:36
    List<AssetTemplate> _getFilteredTemplates(List<AssetTemplate> templates) {
      return templates.where((t) {
        final matchesTags = _selectedTags.isEmpty ||
            _selectedTags.every((tag) => t.tags.contains(tag));
        return matchesName && matchesTags;
      }).toList();
    }
    ```
  </Step>

  <Step title="Search by Name">
    Use the search bar to find specific templates by name or description.
  </Step>

  <Step title="View Template Details">
    Click on a template card to see:

    * Detailed description
    * Included custom fields
    * Download count
    * Creation date
    * Author information
  </Step>
</Steps>

## Using Templates

### Installing from Marketplace

To add a template to your library:

<Steps>
  <Step title="Select Template">
    Browse the marketplace and find the template that matches your needs.
  </Step>

  <Step title="Preview Fields">
    Review the custom field definitions included in the template. These will define what information you can track for each item.
  </Step>

  <Step title="Add to Library">
    Click "Save to Library" or "Install" to add the template to your personal collection.

    ```dart theme={null}
    // From template_provider.dart:86
    Future<bool> saveTemplateToLibrary(AssetTemplate template) async {
      try {
        _service.trackDownload(template.id);
        
        // Optimistic update
        final index = _marketTemplates.indexWhere((t) => t.id == template.id);
        if (index != -1) {
          _marketTemplates[index].downloadCount++;
        }
        
        await fetchUserLibrary();
        notifyListeners();
        return true;
      } catch (e) {
        _errorMessage = e.toString();
        return false;
      }
    }
    ```
  </Step>

  <Step title="Create Collection">
    Navigate to your library and use the template to create a new collection with the predefined structure.
  </Step>
</Steps>

### Template Components

Each template includes:

<Accordion title="Custom Field Definitions">
  Templates come with pre-configured custom fields tailored to the collection type. For example, a video game template might include:

  * Platform (dropdown)
  * Condition (dropdown)
  * Purchase Price (price)
  * Purchase Date (date)
  * Complete-in-Box (boolean)
  * UPC Code (text)

  See [Custom Fields](/advanced/custom-fields) for more details on field types.
</Accordion>

<Accordion title="Asset Type Configuration">
  Defines the categories and subcategories for organizing items within the collection.
</Accordion>

<Accordion title="Metadata">
  Templates include descriptive information:

  ```json theme={null}
  {
    "id": "video_games_collection",
    "name": "Video Game Collection",
    "description": "Track your game library with platform, condition, and value tracking",
    "tags": ["gaming", "collectibles", "entertainment"],
    "downloadCount": 1247,
    "createdAt": "2024-01-15T10:30:00Z"
  }
  ```
</Accordion>

## Creating Collections from Templates

Once a template is in your library:

1. **Select the Template** - Choose from your saved templates
2. **Name Your Collection** - Give your collection a unique name
3. **Customize (Optional)** - Modify field definitions or add new ones
4. **Start Adding Items** - Begin populating your collection with assets

<Note>
  Collections created from templates are independent copies. Changes to the original template won't affect your existing collections.
</Note>

## Publishing Your Own Templates

Share your collection structures with the community:

<Steps>
  <Step title="Prepare Your Collection">
    Create a collection with well-defined custom fields and organizational structure. Ensure it represents a reusable pattern.
  </Step>

  <Step title="Open Template Editor">
    Navigate to Templates → Create or use the "Publicar Plantilla" button.
  </Step>

  <Step title="Configure Template Metadata">
    Fill in the template information:

    ```dart theme={null}
    // Template structure
    {
      "id": "unique_template_id",
      "name": "Descriptive Name",
      "description": "Clear explanation of use case",
      "tags": ["category1", "category2"],
      "fields": [
        // Custom field definitions
      ]
    }
    ```
  </Step>

  <Step title="Add Custom Fields">
    Define all custom fields that should be included:

    * Field name and type
    * Validation rules
    * Default values
    * Helper text

    Reference the [Custom Fields](/advanced/custom-fields) documentation for field type options.
  </Step>

  <Step title="Tag Appropriately">
    Add relevant tags to help users discover your template. Use existing tags when possible for better organization.
  </Step>

  <Step title="Publish to Marketplace">
    Submit your template for review. The system will:

    ```dart theme={null}
    // From template_provider.dart:56
    Future<bool> publishTemplateToMarket(AssetTemplate template) async {
      _setLoading(true);
      try {
        await _service.publishTemplate(template);
        _errorMessage = null;
        notifyListeners();
        return true;
      } catch (e) {
        _errorMessage = e.toString();
        rethrow;
      } finally {
        _setLoading(false);
      }
    }
    ```
  </Step>
</Steps>

### Template Publishing Guidelines

<AccordionGroup>
  <Accordion title="Quality Standards">
    * **Clear Purpose**: Template should solve a specific use case
    * **Complete Fields**: Include all essential custom fields
    * **Good Descriptions**: Write clear, helpful descriptions
    * **Appropriate Tags**: Use relevant, existing tags
    * **Tested**: Verify the template works as expected
  </Accordion>

  <Accordion title="Naming Conventions">
    * Use descriptive, searchable names
    * Avoid generic terms like "My Template"
    * Include the collection type (e.g., "Vinyl Record Collection")
    * Keep names concise but informative
  </Accordion>

  <Accordion title="Field Design">
    * Include only universally applicable fields
    * Use appropriate field types for data validation
    * Provide sensible default values when applicable
    * Consider common use cases for your target audience
  </Accordion>
</AccordionGroup>

## Managing Your Template Library

### Personal Library

Your template library shows all saved templates:

```dart theme={null}
// From template_provider.dart:74
Future<void> fetchUserLibrary() async {
  _setLoading(true);
  try {
    _userLibrary = await _service.getUserLibrary();
    _errorMessage = null;
  } catch (e) {
    _errorMessage = e.toString();
  } finally {
    _setLoading(false);
  }
}
```

Access your library to:

* View saved templates
* Create new collections
* Modify template copies
* Remove unused templates

### Template Updates

When template authors publish updates:

<Warning>
  Existing collections created from a template are not automatically updated. You'll need to create a new collection from the updated template or manually apply changes.
</Warning>

## Template Marketplace Features

### Download Tracking

Template popularity is tracked via download counts:

```dart theme={null}
// From template_service.dart:36
Future<void> trackDownload(String templateId) async {
  try {
    final url = '/templates/$templateId/download';
    await _dio.post(url);
  } on DioException catch (e) {
    print("Error tracking download: ${e.message}");
  }
}
```

This helps users identify popular and trusted templates.

### Template Detail View

Full template information is loaded on-demand:

```dart theme={null}
// From template_service.dart:51
Future<AssetTemplate> getTemplateById(String id) async {
  try {
    final url = '/templates/detail/$id';
    final response = await _dio.get(url);
    
    if (response.statusCode == 200) {
      return AssetTemplate.fromJson(response.data);
    } else {
      throw Exception('Template not found');
    }
  } on DioException catch (e) {
    throw _handleError(e);
  }
}
```

This provides complete field definitions and configuration details.

## Best Practices

<CardGroup cols={2}>
  <Card title="For Template Users" icon="user">
    * Preview all fields before installing
    * Check download counts and ratings
    * Read descriptions carefully
    * Customize after creation as needed
  </Card>

  <Card title="For Template Creators" icon="wand-magic-sparkles">
    * Test with real data before publishing
    * Use clear, descriptive names
    * Include comprehensive field sets
    * Update templates based on feedback
  </Card>
</CardGroup>

## Common Use Cases

<AccordionGroup>
  <Accordion title="Video Game Collection">
    Track your game library with fields for:

    * Platform and region
    * Physical condition
    * Box and manual status
    * Purchase information
    * Current market value
  </Accordion>

  <Accordion title="Book Library">
    Organize your reading collection with:

    * ISBN and publication info
    * Author and series
    * Edition and printing
    * Reading status
    * Lending tracking
  </Accordion>

  <Accordion title="Electronics Inventory">
    Manage tech assets with:

    * Model and serial numbers
    * Warranty information
    * Purchase date and price
    * Depreciation tracking
    * Maintenance schedules
  </Accordion>

  <Accordion title="Tool Collection">
    Track workshop equipment with:

    * Brand and model
    * Condition ratings
    * Location in workshop
    * Maintenance logs
    * Replacement cost
  </Accordion>
</AccordionGroup>

## Troubleshooting

<Accordion title="Template Not Loading">
  If a template fails to load:

  1. Check your internet connection
  2. Refresh the marketplace
  3. Try viewing the template details
  4. Contact the template author if the issue persists
</Accordion>

<Accordion title="Missing Fields After Installation">
  If fields are missing:

  1. Verify the template includes those fields in the detail view
  2. Check if you're viewing the correct collection
  3. Ensure the template installation completed successfully
  4. Try reinstalling the template
</Accordion>

## Next Steps

<CardGroup cols={2}>
  <Card title="Custom Fields" icon="list" href="/advanced/custom-fields">
    Learn about creating custom field definitions
  </Card>

  <Card title="Plugins" icon="puzzle-piece" href="/advanced/plugins">
    Extend functionality with plugins
  </Card>

  <Card title="Asset Types" icon="tag" href="/collections/asset-types">
    Configure asset type hierarchies
  </Card>

  <Card title="Bulk Operations" icon="layer-group" href="/items/bulk-operations">
    Efficiently manage multiple items
  </Card>
</CardGroup>
