Compartir a través de


Configurar la plantilla web de resultados de búsqueda por facetas desde su portal

Puede ver y buscar archivos adjuntos de artículos de conocimiento en el portal, según la búsqueda de Dataverse. Para ello, debe configurar la plantilla web de resultados de búsqueda por facetas en su portal.

  1. En el mapa del sitio de Administración del portal, área Contenido, seleccione Plantillas web.
  2. Desde la lista desplegable Plantillas web activas, seleccione la plantilla web de su artículo de conocimiento.
  3. En la página Plantilla Web en la pestaña General, agregue el siguiente fragmento de código al campo Fuente:
                            {{#if relatedAttachments}}
								{{#each relatedAttachments}}
									<li class="note-item">
									{{#if isImage}}
										<a id="kbattachment-{{entityID}}" href="javascript:downloadKbAttachmentFile('kbattachment-{{entityID}}', '{{title}}', {{fileSize}}, '{{fileType}}', '{{downloadBlockUrl}}', '{{initializeDownloadUrl}}')"><span class="glyphicon glyphicon-file" aria-hidden="true"></span>&nbsp;{{title}}</a>
									{{else}}
										<a id="kbattachment-{{entityID}}" title="{{title}}" href="javascript:downloadKbAttachmentFile('kbattachment-{{entityID}}', '{{title}}', {{fileSize}}, '{{fileType}}', '{{downloadBlockUrl}}', '{{initializeDownloadUrl}}')"><span class="glyphicon glyphicon-file" aria-hidden="true"></span>&nbsp;{{title}}</a>
									{{/if}}
									<p class="fragment text-muted">{{{fragment}}}</p>
									</li>
								{{/each}}
							{{/if}}
<script type="text/javascript">
		function downloadKbAttachmentFile(attachmentElementId, fileName, fileSize, mimeType, downloadBlockUrl, initializeUrl) {
					// Download block API supports max 4MB block size
					const blockSizeInBytes = 4096 * 1024;
					const totalNumberOfBlocks = parseInt(fileSize / blockSizeInBytes + 1);
					var fileContinuationToken = "";
					var contentString = "";
					var numberOfBlocksDownloaded = 0;
					var blockNumberToContentMap = {};
					function downloadBlockCallback(i, result) {
						numberOfBlocksDownloaded++;
						blockNumberToContentMap[i] = result;
						if (numberOfBlocksDownloaded == totalNumberOfBlocks) {
							for (var j = 0; j < totalNumberOfBlocks; j++) {
								contentString += blockNumberToContentMap[j];
							}
							var isImage = mimeType.startsWith('image/');
							const attachmentElement = document.getElementById(attachmentElementId);
							if (isImage) {
								const bodyByteString = atob(contentString);
								const bodyBuffer = new ArrayBuffer(bodyByteString.length);
								const bodyView = new Uint8Array(bodyBuffer);
								for (var k = 0; k < bodyByteString.length; k++) {
									bodyView[k] = bodyByteString.charCodeAt(k);
								}
								var imageUrl = URL.createObjectURL(new Blob([bodyBuffer], { type: mimeType }));
								attachmentElement.href = imageUrl;
								attachmentElement.target = "_blank";
							}
							else {
								const linkSource = 'data:' + mimeType + ';base64,' + contentString;
								attachmentElement.href = linkSource;
								attachmentElement.download = fileName;
							}
							attachmentElement.click();
						}
					}
					shell.ajaxSafePost({
						type: 'GET',
						url: initializeUrl,
						success: function (result) {
							fileContinuationToken = encodeURIComponent(result);
							for (var i = 0; i < totalNumberOfBlocks; i++) {
								url = downloadBlockUrl + "&blockNumber=" + i + "&fileContinuationToken=" + fileContinuationToken + "&blockSize=" + blockSizeInBytes;
								var x = downloadBlockCallback.bind(this,i);
								shell.ajaxSafePost({
									type: 'GET',
									url: url,
									success: (result) => { x(result) }
								});
							}
						}
					});
				}
		</script>
  1. Seleccione Guardar.

Consulte también

Agregar un adjunto de archivo a un artículo de conocimiento
Actualizar datos adjuntos de artículos de conocimientos para el portalMostrar los archivos adjuntos con los artículos de conocimientos